SlideShare a Scribd company logo
JAVA NETWORKING
Mobile Programming
NETWORKTODAY
NETWORKTODAY
NETWORKTODAY
NETWORKTODAY
NETWORK IS…
WEB IS BIGGER NETWORK
HOWTHEY COMMUNICATE?
PROTOCOL
ILLUSTRATION
IP: 192.168.1.1
IP: 192.168.1.2 IP: 192.168.1.3 IP: 192.168.1.4 IP: 192.168.1.5 IP: 192.168.1.6
DETAILED ILLUSTRATION
Logical Path
Physical Layer
Internet Layer (IP) Internet Layer (IP)
Transport Layer (TCP/IP) Transport Layer (TCP/IP)
Application Layer Application Layer
TERMINOLOGY
• Transmission Control Protocol
• User Datagram Protocol
• Port
• URL
• HTTP
MORETERMINOLOGY
• HTML
• XML
• FTP
• SMTP
• POP3/IMAP
PROTOCOL SCANNER
1 import java.net.*;
2
3 public class ProtocolTester {
4 public static void main(String[] args) {
5 String url = "www.bl.ac.id";
6
7 testProtocol("http://" + url);
8 testProtocol("https://" + url);
9 testProtocol("ftp://" + url);
10 testProtocol("nfs://" + url);
11 testProtocol("telnet://" + url);
12 testProtocol("mailto:rizafahmi@gmail.com");
13
14
15 }
16
17 private static void testProtocol (String url) {
18 try {
19 URL u = new URL(url);
20 System.out.println(u.getProtocol() + " is supported.");
21 } catch (MalformedURLException e) {
22 String protocol = url.substring(0, url.indexOf(":"));
23 System.out.println(protocol + " is not supported");
24 }
25 }
26 }
YOURTURN!
PORT SCANNER
1 import java.net.*;
2 import java.io.*;
3
4 public class LowPortScanner {
5 public static void main(String[] args) {
6 String host = "www.bl.ac.id";
7 System.out.println("Tunggu ya, sedang
mendeteksi...");
8
9 for (int i = 1; i < 100; i++) {
10 try {
11 Socket s = new Socket(host, i);
12 System.out.println("Port " + i + " digunakan
" + host);
13 } catch (UnknownHostException e) {
14 System.err.println(e);
15 } catch (IOException e) {
16 System.out.println("Port " + i + " Tidak
Digunakan " + host);
17 }
18 }
19 }
20 }
YOURTURN!
DOWNLOAD AND PARSE
HTML PAGE
1 import java.net.*;
2 import java.io.*;
3 public class SourceViewer {
4
5 public static void main (String[] args) {
6 if (args.length > 0) {
7 InputStream in = null;
8 try {
9 URL u = new URL(args[0]);
10 in = u.openStream();
11
12 in = new BufferedInputStream(in);
13 Reader r = new InputStreamReader(in);
14 int c;
15 while((c = r.read()) != -1) {
16 System.out.print((char) c);
17 }
18 } catch (MalformedURLException e) {
19 System.out.print(args[0] + " is not
parseable URL");
20 } catch (IOException e) {
21 System.err.println(e);
22 } finally {
23 if (in != null) {
24 try {
25 in.close();
26 } catch (IOException e) {
27 // ignore
28 }
29 }
30 }
31
32 }
33 }
34 }
> java SourceViewer http://www.bl.ac.id/
<!DOCTYPE html>
<html lang="id-ID">
<head>
<meta charset="UTF-8" />
<title>Universitas Budi Luhur</title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="http://www.budiluhur.ac.id/xmlrpc.php" />
<script type="text/javascript" src="http://www.budiluhur.ac.id/wp-
content/themes/new-bl/images/jquery.js"></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://
www.
budiluhur.ac.id/xmlrpc.php?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://
www.
budiluhur.ac.id/wp-includes/wlwmanifest.xml">
<link rel="index" title="Universitas Budi Luhur" href="http://
www.budiluhur.ac.
id/">
<meta name="generator" content="WordPress 3.0.1">
…
YOURTURN!
SENDING EMAIL
1 import java.util.*;
2 import javax.mail.*;
3 import javax.mail.internet.*;
4 import javax.activation.*;
5
6 public class SendEmail {
7 public static void main (String[] args) {
8 String to = "rizafahmi@gmail.com";
9 String from = “riza@appsco.id";
10 String host = "192.168.1.134";
11 Properties properties = System.getProperties();
12 properties.setProperty("mail.smtp.host", host);
13 properties.put("mail.smtp.port", 1025);
14 Session session = Session.getDefaultInstance(properties);
15
16 try {
17 MimeMessage message = new MimeMessage(session);
18 message.setFrom(new InternetAddress(from));
19 message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
20 message.setSubject("This is the subject line");
21 message.setText("This is actual message");
22
23 Transport.send(message);
24 System.out.println("Sent message successfully...");
25 } catch (MessagingException e) {
26 e.printStackTrace();
27 }
28 }
29 }
30
RECEIVING EMAIL
1 import java.util.Properties;
2 import javax.mail.*;
3 import javax.mail.internet.*;
4
5 public class POP3Client {
6 public static void main(String[] args) throws Exception {
7
8 Properties properties = getProperties();
9
10 Session session = getSession(properties);
11
12 Store store = connectingStore(session);
13
14 Folder inbox = getInboxFolder(store, "Inbox");
15
16 Message[] messages = inbox.getMessages();
17
18 if (messages.length == 0)
19 System.out.println("No message found");
20
21 System.out.println(messages.length);
22
23 inbox.close(true);
24 store.close();
25 }
26
27 private static Properties getProperties() {
28
29 Properties properties = System.getProperties();
30 properties.put("mail.pop3.port", 995);
31 properties.put("mail.pop3.ssl.enable", true);
32 properties.setProperty("mail.pop3.ssl.trust", "*");
33
34 return properties;
35 }
36
37 private static Session getSession(Properties properties) {
38 Session session = Session.getDefaultInstance(properties);
39
40 return session;
41 }
42
43 private static Store connectingStore(Session session) throws
Exception {
44 String host = "pop.zoho.com";
45 String username = "riza@appsco.id";
46 String password = "123456";
47
48 Store store = session.getStore("pop3");
49 store.connect(host, 995, username, password);
50
51 return store;
52 }
53
54 private static Folder getInboxFolder(Store store, String
folder) throws
55 Exception {
56 Folder inbox = store.getFolder("Inbox");
57 inbox.open(Folder.READ_ONLY);
58
59 return inbox;
60 }
61 }
YOURTURN!
LET’S DO CHAT!
Mobile Programming - Network Universitas Budi Luhur
PROTOCOL
1 import java.net.*;
2 import java.io.*;
3
4 public class KnockKnockProtocol {
5 private static final int WAITING = 0;
6 private static final int SENTKNOCKKNOCK = 1;
7 private static final int SENTCLUE = 2;
8 private static final int ANOTHER = 3;
9 private static final int NUMJOKES = 5;
10
11 private int state = WAITING;
12 private int currentJoke = 0;
13 private String[] clues = {"Bessarion", "Colby", "Gary", "Teodor", "Kamala"};
14 private String[] answers = {"Matiin AC dong, dingin nih!", "Lagi pusing
15 ya?", "Kelihatan ngga?", "Semoga sukses",
16 "Bazinga!"};
17
18 public String processInput(String inputString) {
19 String outputString = null;
20
21 if (state == WAITING) {
22 outputString = "Tok, tok, tok";
23 state = SENTKNOCKKNOCK;
24 } else if (state == SENTKNOCKKNOCK) {
25 if (inputString.equalsIgnoreCase("Siapa?")) {
26 outputString = clues[currentJoke];
27 state = SENTCLUE;
28 } else {
29 outputString = "Seharusnya kamu menjawab "Siapa?"! " + "Yuk kita
30 coba lagi. Tok, tok, tok";
31 state = ANOTHER;
32 }
33 } else if (state == SENTCLUE) {
34 if (inputString.equalsIgnoreCase(clues[currentJoke] + " siapa?")) {
35 outputString = answers[currentJoke] + " Ingin orang lain? (y/n)";
36 state = ANOTHER;
37 } else {
38 outputString = "Seharusnya "" + clues[currentJoke] + " siapa?"" +
39 "! Coba lagi yaa. Tok, tok, tok";
40 state = SENTKNOCKKNOCK;
41 }
42 } else if (state == ANOTHER) {
43 if (inputString.equalsIgnoreCase("y")) {
44 outputString = "Tok, tok, tok";
45 if (currentJoke == (NUMJOKES - 1))
46 currentJoke = 0;
47 else
48 currentJoke++;
49 state = SENTKNOCKKNOCK;
50 } else {
51 outputString = "Bye bye!";
52 state = WAITING;
53 }
54
55 }
56
57 return outputString;
58 }
59 }
SERVER
1 import java.net.*;
2 import java.io.*;
3
4 public class KnockKnockServer {
5 public static void main(String[] args) throws IOException {
6 ServerSocket serverSocket = null;
7
8 try {
9 serverSocket = new ServerSocket(4444);
10 System.out.println("Ok, server ready!");
11 } catch (IOException e) {
12 System.err.println("port 4444 tidak dapat digunakan.");
13 System.exit(1);
14 }
15
16 Socket clientSocket = null;
17 try {
18 clientSocket = serverSocket.accept();
19 } catch (IOException e) {
20 System.err.println("Client gagal menggunakan port.");
21 System.exit(1);
22 }
23
24 PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
25
26 BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.
27 getInputStream()));
28
29 String inputLine, outputLine;
30
31 KnockKnockProtocol kkp = new KnockKnockProtocol();
32 outputLine = kkp.processInput(null);
33 out.println(outputLine);
34
35 while((inputLine = in.readLine()) != null) {
36 outputLine = kkp.processInput(inputLine);
37 out.println(outputLine);
38
39 if (outputLine.equals("Bye bye!"))
40 break;
41 }
42
43 out.close();
44 in.close();
45 clientSocket.close();
46 serverSocket.close();
47 }
48 }
CLIENT
1 import java.io.*;
2 import java.net.*;
3
4 public class KnockKnockClient {
5 public static void main(String[] args) throws IOException {
6 Socket kkSocket = null;
7 PrintWriter out = null;
8 BufferedReader in = null;
9
10 try {
11 kkSocket = new Socket("localhost", 4444);
12 out = new PrintWriter(kkSocket.getOutputStream(), true);
13 in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())
14 );
15
16 } catch (UnknownHostException e) {
17 System.err.println("Host localhost tidak ditemukan.");
18 System.exit(1);
19 } catch (IOException e) {
20 System.err.println("Koneksi Input output ke localhost gagal.");
21 System.exit(1);
22 }
23
24 BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)
25 );
26 String fromServer;
27 String fromUser;
28
29 while((fromServer = in.readLine()) != null) {
30 System.out.println("Server: " + fromServer);
31 if (fromServer.equals("Bye bye!"))
32 break;
33
34 fromUser = stdIn.readLine();
35
36 if (fromUser != null) {
37 System.out.println("Client: " + fromUser);
38 out.println(fromUser);
39 }
40 }
41
42 out.close();
43 in.close();
44 stdIn.close();
45 kkSocket.close();
46 }
47 }
YOURTURN!

More Related Content

What's hot (20)

PPTX
My sql failover test using orchestrator
YoungHeon (Roy) Kim
 
PPTX
[4] 아두이노와 인터넷
Chiwon Song
 
PPT
Owin e o Projeto Katana
Andre Carlucci
 
PDF
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum
 
PDF
Lab 1 my sql tutorial
Manuel Contreras
 
PDF
Elastic 101 tutorial - Percona Europe 2018
Antonios Giannopoulos
 
DOCX
Inventory program in mca p1
rameshvvv
 
PPTX
Openstack Testbed_ovs_virtualbox_devstack_single node
Yongyoon Shin
 
PDF
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
PROIDEA
 
PDF
MySQL replication & cluster
elliando dias
 
PDF
Hibernate Import.Sql I18n
yifi2009
 
PPTX
Query logging with proxysql
YoungHeon (Roy) Kim
 
PDF
Scalable Socket Server by Aryo
Agate Studio
 
ODT
Squid file
Nalin Peiris
 
PDF
KSDG-iSlide App 開發心得分享
Chia Wei Tsai
 
PDF
A little waf
yang bingwu
 
PDF
WebTalk - Implementing Web Services with a dedicated Java daemon
Geert Van Pamel
 
PDF
The Ring programming language version 1.7 book - Part 52 of 196
Mahmoud Samir Fayed
 
PDF
ikh331-06-distributed-programming
Anung Ariwibowo
 
PDF
Percona XtraDB 集群内部
YUCHENG HU
 
My sql failover test using orchestrator
YoungHeon (Roy) Kim
 
[4] 아두이노와 인터넷
Chiwon Song
 
Owin e o Projeto Katana
Andre Carlucci
 
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum
 
Lab 1 my sql tutorial
Manuel Contreras
 
Elastic 101 tutorial - Percona Europe 2018
Antonios Giannopoulos
 
Inventory program in mca p1
rameshvvv
 
Openstack Testbed_ovs_virtualbox_devstack_single node
Yongyoon Shin
 
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
PROIDEA
 
MySQL replication & cluster
elliando dias
 
Hibernate Import.Sql I18n
yifi2009
 
Query logging with proxysql
YoungHeon (Roy) Kim
 
Scalable Socket Server by Aryo
Agate Studio
 
Squid file
Nalin Peiris
 
KSDG-iSlide App 開發心得分享
Chia Wei Tsai
 
A little waf
yang bingwu
 
WebTalk - Implementing Web Services with a dedicated Java daemon
Geert Van Pamel
 
The Ring programming language version 1.7 book - Part 52 of 196
Mahmoud Samir Fayed
 
ikh331-06-distributed-programming
Anung Ariwibowo
 
Percona XtraDB 集群内部
YUCHENG HU
 

Viewers also liked (12)

PDF
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Riza Fahmi
 
PPTX
Sony lazuardi native mobile app with javascript
PHP Indonesia
 
PDF
APPSCoast Pitch Deck
Riza Fahmi
 
PDF
Meteor Talk At TokoPedia
Riza Fahmi
 
PDF
Muhammad azamuddin introduction-to-reactjs
PHP Indonesia
 
PDF
React Fundamentals - Jakarta JS, Apr 2016
Simon Sturmer
 
PDF
Styling Your React App
Riza Fahmi
 
PDF
Fellow Developers, Let's Discover Your Superpower
Riza Fahmi
 
PDF
Serverless NodeJS With AWS Lambda
Riza Fahmi
 
PPTX
Basic Operating System
Nizar Lazuardy Firmansyah
 
PDF
React Webinar With CodePolitan
Riza Fahmi
 
PDF
Team 101: How to Build The A Team For Your Startup
Riza Fahmi
 
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Riza Fahmi
 
Sony lazuardi native mobile app with javascript
PHP Indonesia
 
APPSCoast Pitch Deck
Riza Fahmi
 
Meteor Talk At TokoPedia
Riza Fahmi
 
Muhammad azamuddin introduction-to-reactjs
PHP Indonesia
 
React Fundamentals - Jakarta JS, Apr 2016
Simon Sturmer
 
Styling Your React App
Riza Fahmi
 
Fellow Developers, Let's Discover Your Superpower
Riza Fahmi
 
Serverless NodeJS With AWS Lambda
Riza Fahmi
 
Basic Operating System
Nizar Lazuardy Firmansyah
 
React Webinar With CodePolitan
Riza Fahmi
 
Team 101: How to Build The A Team For Your Startup
Riza Fahmi
 
Ad

Similar to Mobile Programming - Network Universitas Budi Luhur (20)

DOCX
201913046 wahyu septiansyah network programing
wahyuseptiansyah
 
PDF
Server1
FahriIrawan3
 
PDF
Construire une application JavaFX 8 avec gradle
Thierry Wasylczenko
 
PPTX
Spring Boot
Jiayun Zhou
 
PDF
#JavaFX.forReal() - ElsassJUG
Thierry Wasylczenko
 
ODP
Java Concurrency
Carol McDonald
 
PDF
Non Blocking I/O for Everyone with RxJava
Frank Lyaruu
 
PDF
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
DOCX
I need you to modify and change the loop in this code without changing.docx
hendriciraida
 
PDF
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
PPTX
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
epamspb
 
PPT
Socket Programming
Sivadon Chaisiri
 
PDF
Laporan multiclient chatting client server
trilestari08
 
PDF
Ipc
deepakittude
 
PPTX
Jdk 7 4-forkjoin
knight1128
 
PDF
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Mumbai B.Sc.IT Study
 
PDF
Testing in android
jtrindade
 
PPTX
Java
박 경민
 
DOCX
I need an explaining for each step in this code and the reason of it-.docx
hendriciraida
 
PPTX
Nantes Jug - Java 7
Sébastien Prunier
 
201913046 wahyu septiansyah network programing
wahyuseptiansyah
 
Server1
FahriIrawan3
 
Construire une application JavaFX 8 avec gradle
Thierry Wasylczenko
 
Spring Boot
Jiayun Zhou
 
#JavaFX.forReal() - ElsassJUG
Thierry Wasylczenko
 
Java Concurrency
Carol McDonald
 
Non Blocking I/O for Everyone with RxJava
Frank Lyaruu
 
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
I need you to modify and change the loop in this code without changing.docx
hendriciraida
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
epamspb
 
Socket Programming
Sivadon Chaisiri
 
Laporan multiclient chatting client server
trilestari08
 
Jdk 7 4-forkjoin
knight1128
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Mumbai B.Sc.IT Study
 
Testing in android
jtrindade
 
I need an explaining for each step in this code and the reason of it-.docx
hendriciraida
 
Nantes Jug - Java 7
Sébastien Prunier
 
Ad

More from Riza Fahmi (20)

PDF
Membangun Aplikasi Web dengan Elixir dan Phoenix
Riza Fahmi
 
PDF
Berbagai Pilihan Karir Developer
Riza Fahmi
 
PDF
Web dan Progressive Web Apps di 2020
Riza Fahmi
 
PDF
Remote Working/Learning
Riza Fahmi
 
PDF
How to learn programming
Riza Fahmi
 
PDF
Rapid App Development with AWS Amplify
Riza Fahmi
 
PDF
Menguak Misteri Module Bundler
Riza Fahmi
 
PDF
Beberapa Web API Menarik
Riza Fahmi
 
PDF
MVP development from software developer perspective
Riza Fahmi
 
PDF
Ekosistem JavaScript di Indonesia
Riza Fahmi
 
PDF
Perkenalan ReasonML
Riza Fahmi
 
PDF
How I Generate Idea
Riza Fahmi
 
PDF
Strategi Presentasi Untuk Developer Workshop Slide
Riza Fahmi
 
PDF
Lesson Learned from Prolific Developers
Riza Fahmi
 
PDF
Clean Code JavaScript
Riza Fahmi
 
PDF
The Future of AI
Riza Fahmi
 
PDF
Chrome Dev Summit 2018 - Personal Take Aways
Riza Fahmi
 
PDF
Essentials and Impactful Features of ES6
Riza Fahmi
 
PDF
Modern Static Site with GatsbyJS
Riza Fahmi
 
PDF
Introduction to ReasonML
Riza Fahmi
 
Membangun Aplikasi Web dengan Elixir dan Phoenix
Riza Fahmi
 
Berbagai Pilihan Karir Developer
Riza Fahmi
 
Web dan Progressive Web Apps di 2020
Riza Fahmi
 
Remote Working/Learning
Riza Fahmi
 
How to learn programming
Riza Fahmi
 
Rapid App Development with AWS Amplify
Riza Fahmi
 
Menguak Misteri Module Bundler
Riza Fahmi
 
Beberapa Web API Menarik
Riza Fahmi
 
MVP development from software developer perspective
Riza Fahmi
 
Ekosistem JavaScript di Indonesia
Riza Fahmi
 
Perkenalan ReasonML
Riza Fahmi
 
How I Generate Idea
Riza Fahmi
 
Strategi Presentasi Untuk Developer Workshop Slide
Riza Fahmi
 
Lesson Learned from Prolific Developers
Riza Fahmi
 
Clean Code JavaScript
Riza Fahmi
 
The Future of AI
Riza Fahmi
 
Chrome Dev Summit 2018 - Personal Take Aways
Riza Fahmi
 
Essentials and Impactful Features of ES6
Riza Fahmi
 
Modern Static Site with GatsbyJS
Riza Fahmi
 
Introduction to ReasonML
Riza Fahmi
 

Recently uploaded (20)

PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Learn Computer Forensics, Second Edition
AnuraShantha7
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Learn Computer Forensics, Second Edition
AnuraShantha7
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 

Mobile Programming - Network Universitas Budi Luhur

  • 7. WEB IS BIGGER NETWORK
  • 10. ILLUSTRATION IP: 192.168.1.1 IP: 192.168.1.2 IP: 192.168.1.3 IP: 192.168.1.4 IP: 192.168.1.5 IP: 192.168.1.6
  • 11. DETAILED ILLUSTRATION Logical Path Physical Layer Internet Layer (IP) Internet Layer (IP) Transport Layer (TCP/IP) Transport Layer (TCP/IP) Application Layer Application Layer
  • 12. TERMINOLOGY • Transmission Control Protocol • User Datagram Protocol • Port • URL • HTTP
  • 13. MORETERMINOLOGY • HTML • XML • FTP • SMTP • POP3/IMAP
  • 15. 1 import java.net.*; 2 3 public class ProtocolTester { 4 public static void main(String[] args) { 5 String url = "www.bl.ac.id"; 6 7 testProtocol("http://" + url); 8 testProtocol("https://" + url); 9 testProtocol("ftp://" + url); 10 testProtocol("nfs://" + url); 11 testProtocol("telnet://" + url); 12 testProtocol("mailto:[email protected]"); 13 14 15 } 16 17 private static void testProtocol (String url) { 18 try { 19 URL u = new URL(url); 20 System.out.println(u.getProtocol() + " is supported."); 21 } catch (MalformedURLException e) { 22 String protocol = url.substring(0, url.indexOf(":")); 23 System.out.println(protocol + " is not supported"); 24 } 25 } 26 }
  • 18. 1 import java.net.*; 2 import java.io.*; 3 4 public class LowPortScanner { 5 public static void main(String[] args) { 6 String host = "www.bl.ac.id"; 7 System.out.println("Tunggu ya, sedang mendeteksi..."); 8 9 for (int i = 1; i < 100; i++) { 10 try { 11 Socket s = new Socket(host, i); 12 System.out.println("Port " + i + " digunakan " + host); 13 } catch (UnknownHostException e) { 14 System.err.println(e); 15 } catch (IOException e) { 16 System.out.println("Port " + i + " Tidak Digunakan " + host); 17 } 18 } 19 } 20 }
  • 21. 1 import java.net.*; 2 import java.io.*; 3 public class SourceViewer { 4 5 public static void main (String[] args) { 6 if (args.length > 0) { 7 InputStream in = null; 8 try { 9 URL u = new URL(args[0]); 10 in = u.openStream(); 11 12 in = new BufferedInputStream(in); 13 Reader r = new InputStreamReader(in); 14 int c; 15 while((c = r.read()) != -1) { 16 System.out.print((char) c); 17 }
  • 22. 18 } catch (MalformedURLException e) { 19 System.out.print(args[0] + " is not parseable URL"); 20 } catch (IOException e) { 21 System.err.println(e); 22 } finally { 23 if (in != null) { 24 try { 25 in.close(); 26 } catch (IOException e) { 27 // ignore 28 } 29 } 30 } 31 32 } 33 } 34 }
  • 23. > java SourceViewer http://www.bl.ac.id/ <!DOCTYPE html> <html lang="id-ID"> <head> <meta charset="UTF-8" /> <title>Universitas Budi Luhur</title> <link rel="profile" href="http://gmpg.org/xfn/11" /> <link rel="pingback" href="http://www.budiluhur.ac.id/xmlrpc.php" /> <script type="text/javascript" src="http://www.budiluhur.ac.id/wp- content/themes/new-bl/images/jquery.js"></script> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http:// www. budiluhur.ac.id/xmlrpc.php?rsd"> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http:// www. budiluhur.ac.id/wp-includes/wlwmanifest.xml"> <link rel="index" title="Universitas Budi Luhur" href="http:// www.budiluhur.ac. id/"> <meta name="generator" content="WordPress 3.0.1"> …
  • 26. 1 import java.util.*; 2 import javax.mail.*; 3 import javax.mail.internet.*; 4 import javax.activation.*; 5 6 public class SendEmail { 7 public static void main (String[] args) { 8 String to = "[email protected]"; 9 String from = “[email protected]"; 10 String host = "192.168.1.134"; 11 Properties properties = System.getProperties(); 12 properties.setProperty("mail.smtp.host", host); 13 properties.put("mail.smtp.port", 1025); 14 Session session = Session.getDefaultInstance(properties); 15
  • 27. 16 try { 17 MimeMessage message = new MimeMessage(session); 18 message.setFrom(new InternetAddress(from)); 19 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); 20 message.setSubject("This is the subject line"); 21 message.setText("This is actual message"); 22 23 Transport.send(message); 24 System.out.println("Sent message successfully..."); 25 } catch (MessagingException e) { 26 e.printStackTrace(); 27 } 28 } 29 } 30
  • 29. 1 import java.util.Properties; 2 import javax.mail.*; 3 import javax.mail.internet.*; 4 5 public class POP3Client { 6 public static void main(String[] args) throws Exception { 7 8 Properties properties = getProperties(); 9 10 Session session = getSession(properties); 11 12 Store store = connectingStore(session); 13 14 Folder inbox = getInboxFolder(store, "Inbox"); 15 16 Message[] messages = inbox.getMessages(); 17 18 if (messages.length == 0) 19 System.out.println("No message found"); 20 21 System.out.println(messages.length); 22 23 inbox.close(true); 24 store.close(); 25 } 26
  • 30. 27 private static Properties getProperties() { 28 29 Properties properties = System.getProperties(); 30 properties.put("mail.pop3.port", 995); 31 properties.put("mail.pop3.ssl.enable", true); 32 properties.setProperty("mail.pop3.ssl.trust", "*"); 33 34 return properties; 35 } 36 37 private static Session getSession(Properties properties) { 38 Session session = Session.getDefaultInstance(properties); 39 40 return session; 41 } 42
  • 31. 43 private static Store connectingStore(Session session) throws Exception { 44 String host = "pop.zoho.com"; 45 String username = "[email protected]"; 46 String password = "123456"; 47 48 Store store = session.getStore("pop3"); 49 store.connect(host, 995, username, password); 50 51 return store; 52 } 53 54 private static Folder getInboxFolder(Store store, String folder) throws 55 Exception { 56 Folder inbox = store.getFolder("Inbox"); 57 inbox.open(Folder.READ_ONLY); 58 59 return inbox; 60 } 61 }
  • 36. 1 import java.net.*; 2 import java.io.*; 3 4 public class KnockKnockProtocol { 5 private static final int WAITING = 0; 6 private static final int SENTKNOCKKNOCK = 1; 7 private static final int SENTCLUE = 2; 8 private static final int ANOTHER = 3; 9 private static final int NUMJOKES = 5; 10 11 private int state = WAITING; 12 private int currentJoke = 0; 13 private String[] clues = {"Bessarion", "Colby", "Gary", "Teodor", "Kamala"}; 14 private String[] answers = {"Matiin AC dong, dingin nih!", "Lagi pusing 15 ya?", "Kelihatan ngga?", "Semoga sukses", 16 "Bazinga!"}; 17
  • 37. 18 public String processInput(String inputString) { 19 String outputString = null; 20 21 if (state == WAITING) { 22 outputString = "Tok, tok, tok"; 23 state = SENTKNOCKKNOCK; 24 } else if (state == SENTKNOCKKNOCK) { 25 if (inputString.equalsIgnoreCase("Siapa?")) { 26 outputString = clues[currentJoke]; 27 state = SENTCLUE; 28 } else { 29 outputString = "Seharusnya kamu menjawab "Siapa?"! " + "Yuk kita 30 coba lagi. Tok, tok, tok"; 31 state = ANOTHER; 32 } 33 } else if (state == SENTCLUE) { 34 if (inputString.equalsIgnoreCase(clues[currentJoke] + " siapa?")) { 35 outputString = answers[currentJoke] + " Ingin orang lain? (y/n)"; 36 state = ANOTHER; 37 } else { 38 outputString = "Seharusnya "" + clues[currentJoke] + " siapa?"" + 39 "! Coba lagi yaa. Tok, tok, tok"; 40 state = SENTKNOCKKNOCK; 41 }
  • 38. 42 } else if (state == ANOTHER) { 43 if (inputString.equalsIgnoreCase("y")) { 44 outputString = "Tok, tok, tok"; 45 if (currentJoke == (NUMJOKES - 1)) 46 currentJoke = 0; 47 else 48 currentJoke++; 49 state = SENTKNOCKKNOCK; 50 } else { 51 outputString = "Bye bye!"; 52 state = WAITING; 53 } 54 55 } 56 57 return outputString; 58 } 59 }
  • 40. 1 import java.net.*; 2 import java.io.*; 3 4 public class KnockKnockServer { 5 public static void main(String[] args) throws IOException { 6 ServerSocket serverSocket = null; 7 8 try { 9 serverSocket = new ServerSocket(4444); 10 System.out.println("Ok, server ready!"); 11 } catch (IOException e) { 12 System.err.println("port 4444 tidak dapat digunakan."); 13 System.exit(1); 14 } 15 16 Socket clientSocket = null; 17 try { 18 clientSocket = serverSocket.accept(); 19 } catch (IOException e) { 20 System.err.println("Client gagal menggunakan port."); 21 System.exit(1); 22 } 23
  • 41. 24 PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); 25 26 BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket. 27 getInputStream())); 28 29 String inputLine, outputLine; 30 31 KnockKnockProtocol kkp = new KnockKnockProtocol(); 32 outputLine = kkp.processInput(null); 33 out.println(outputLine); 34 35 while((inputLine = in.readLine()) != null) { 36 outputLine = kkp.processInput(inputLine); 37 out.println(outputLine); 38 39 if (outputLine.equals("Bye bye!")) 40 break; 41 } 42 43 out.close(); 44 in.close(); 45 clientSocket.close(); 46 serverSocket.close(); 47 } 48 }
  • 43. 1 import java.io.*; 2 import java.net.*; 3 4 public class KnockKnockClient { 5 public static void main(String[] args) throws IOException { 6 Socket kkSocket = null; 7 PrintWriter out = null; 8 BufferedReader in = null; 9 10 try { 11 kkSocket = new Socket("localhost", 4444); 12 out = new PrintWriter(kkSocket.getOutputStream(), true); 13 in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()) 14 ); 15 16 } catch (UnknownHostException e) { 17 System.err.println("Host localhost tidak ditemukan."); 18 System.exit(1); 19 } catch (IOException e) { 20 System.err.println("Koneksi Input output ke localhost gagal."); 21 System.exit(1); 22 } 23
  • 44. 24 BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in) 25 ); 26 String fromServer; 27 String fromUser; 28 29 while((fromServer = in.readLine()) != null) { 30 System.out.println("Server: " + fromServer); 31 if (fromServer.equals("Bye bye!")) 32 break; 33 34 fromUser = stdIn.readLine(); 35 36 if (fromUser != null) { 37 System.out.println("Client: " + fromUser); 38 out.println(fromUser); 39 } 40 } 41 42 out.close(); 43 in.close(); 44 stdIn.close(); 45 kkSocket.close(); 46 } 47 }