SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
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!
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!

Contenu connexe

Tendances

My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestratorYoungHeon (Roy) Kim
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷Chiwon Song
 
Owin e o Projeto Katana
Owin e o Projeto KatanaOwin e o Projeto Katana
Owin e o Projeto KatanaAndre Carlucci
 
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #16 - Retrofit 2 by Kristijan JurkovicInfinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #16 - Retrofit 2 by Kristijan JurkovicInfinum
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Antonios Giannopoulos
 
Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1rameshvvv
 
Openstack Testbed_ovs_virtualbox_devstack_single node
Openstack Testbed_ovs_virtualbox_devstack_single nodeOpenstack Testbed_ovs_virtualbox_devstack_single node
Openstack Testbed_ovs_virtualbox_devstack_single nodeYongyoon Shin
 
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...PROIDEA
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & clusterelliando dias
 
Hibernate Import.Sql I18n
Hibernate Import.Sql I18nHibernate Import.Sql I18n
Hibernate Import.Sql I18nyifi2009
 
Scalable Socket Server by Aryo
Scalable Socket Server by AryoScalable Socket Server by Aryo
Scalable Socket Server by AryoAgate Studio
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享Chia Wei Tsai
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonGeert Van Pamel
 
The Ring programming language version 1.7 book - Part 52 of 196
The Ring programming language version 1.7 book - Part 52 of 196The Ring programming language version 1.7 book - Part 52 of 196
The Ring programming language version 1.7 book - Part 52 of 196Mahmoud Samir Fayed
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 
Percona XtraDB 集群内部
Percona XtraDB 集群内部Percona XtraDB 集群内部
Percona XtraDB 集群内部YUCHENG HU
 

Tendances (20)

My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
Owin e o Projeto Katana
Owin e o Projeto KatanaOwin e o Projeto Katana
Owin e o Projeto Katana
 
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #16 - Retrofit 2 by Kristijan JurkovicInfinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
 
Lab 1 my sql tutorial
Lab 1 my sql tutorial Lab 1 my sql tutorial
Lab 1 my sql tutorial
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
 
Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1
 
Openstack Testbed_ovs_virtualbox_devstack_single node
Openstack Testbed_ovs_virtualbox_devstack_single nodeOpenstack Testbed_ovs_virtualbox_devstack_single node
Openstack Testbed_ovs_virtualbox_devstack_single node
 
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
[CONFidence 2016]: Alex Plaskett, Georgi Geshev - QNX: 99 Problems but a Micr...
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
 
Hibernate Import.Sql I18n
Hibernate Import.Sql I18nHibernate Import.Sql I18n
Hibernate Import.Sql I18n
 
Query logging with proxysql
Query logging with proxysqlQuery logging with proxysql
Query logging with proxysql
 
Scalable Socket Server by Aryo
Scalable Socket Server by AryoScalable Socket Server by Aryo
Scalable Socket Server by Aryo
 
Squid file
Squid fileSquid file
Squid file
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享
 
A little waf
A little wafA little waf
A little waf
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
 
The Ring programming language version 1.7 book - Part 52 of 196
The Ring programming language version 1.7 book - Part 52 of 196The Ring programming language version 1.7 book - Part 52 of 196
The Ring programming language version 1.7 book - Part 52 of 196
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
Percona XtraDB 集群内部
Percona XtraDB 集群内部Percona XtraDB 集群内部
Percona XtraDB 集群内部
 

En vedette

Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapakBrief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapakRiza Fahmi
 
Sony lazuardi native mobile app with javascript
Sony lazuardi   native mobile app with javascriptSony lazuardi   native mobile app with javascript
Sony lazuardi native mobile app with javascriptPHP Indonesia
 
APPSCoast Pitch Deck
APPSCoast Pitch DeckAPPSCoast Pitch Deck
APPSCoast Pitch DeckRiza Fahmi
 
Meteor Talk At TokoPedia
Meteor Talk At TokoPediaMeteor Talk At TokoPedia
Meteor Talk At TokoPediaRiza Fahmi
 
Muhammad azamuddin introduction-to-reactjs
Muhammad azamuddin   introduction-to-reactjsMuhammad azamuddin   introduction-to-reactjs
Muhammad azamuddin introduction-to-reactjsPHP Indonesia
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016Simon Sturmer
 
Styling Your React App
Styling Your React AppStyling Your React App
Styling Your React AppRiza Fahmi
 
Fellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your SuperpowerFellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your SuperpowerRiza Fahmi
 
Serverless NodeJS With AWS Lambda
Serverless NodeJS With AWS LambdaServerless NodeJS With AWS Lambda
Serverless NodeJS With AWS LambdaRiza Fahmi
 
React Webinar With CodePolitan
React Webinar With CodePolitanReact Webinar With CodePolitan
React Webinar With CodePolitanRiza Fahmi
 
Team 101: How to Build The A Team For Your Startup
Team 101: How to Build The A Team For Your StartupTeam 101: How to Build The A Team For Your Startup
Team 101: How to Build The A Team For Your StartupRiza Fahmi
 

En vedette (12)

Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapakBrief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
 
Sony lazuardi native mobile app with javascript
Sony lazuardi   native mobile app with javascriptSony lazuardi   native mobile app with javascript
Sony lazuardi native mobile app with javascript
 
APPSCoast Pitch Deck
APPSCoast Pitch DeckAPPSCoast Pitch Deck
APPSCoast Pitch Deck
 
Meteor Talk At TokoPedia
Meteor Talk At TokoPediaMeteor Talk At TokoPedia
Meteor Talk At TokoPedia
 
Muhammad azamuddin introduction-to-reactjs
Muhammad azamuddin   introduction-to-reactjsMuhammad azamuddin   introduction-to-reactjs
Muhammad azamuddin introduction-to-reactjs
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016
 
Styling Your React App
Styling Your React AppStyling Your React App
Styling Your React App
 
Fellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your SuperpowerFellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your Superpower
 
Serverless NodeJS With AWS Lambda
Serverless NodeJS With AWS LambdaServerless NodeJS With AWS Lambda
Serverless NodeJS With AWS Lambda
 
Basic Operating System
Basic Operating SystemBasic Operating System
Basic Operating System
 
React Webinar With CodePolitan
React Webinar With CodePolitanReact Webinar With CodePolitan
React Webinar With CodePolitan
 
Team 101: How to Build The A Team For Your Startup
Team 101: How to Build The A Team For Your StartupTeam 101: How to Build The A Team For Your Startup
Team 101: How to Build The A Team For Your Startup
 

Similaire à Mobile Programming - Network Universitas Budi Luhur

201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programingwahyuseptiansyah
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaFrank Lyaruu
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxhendriciraida
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"epamspb
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client servertrilestari08
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Mumbai B.Sc.IT Study
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
I need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docxI need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docxhendriciraida
 

Similaire à Mobile Programming - Network Universitas Budi Luhur (20)

201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
 
Server1
Server1Server1
Server1
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docx
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
 
Ipc
IpcIpc
Ipc
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
 
Testing in android
Testing in androidTesting in android
Testing in android
 
Java
JavaJava
Java
 
I need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docxI need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docx
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 

Plus de Riza Fahmi

Membangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan PhoenixMembangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan PhoenixRiza Fahmi
 
Berbagai Pilihan Karir Developer
Berbagai Pilihan Karir DeveloperBerbagai Pilihan Karir Developer
Berbagai Pilihan Karir DeveloperRiza Fahmi
 
Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020Riza Fahmi
 
Remote Working/Learning
Remote Working/LearningRemote Working/Learning
Remote Working/LearningRiza Fahmi
 
How to learn programming
How to learn programmingHow to learn programming
How to learn programmingRiza Fahmi
 
Rapid App Development with AWS Amplify
Rapid App Development with AWS AmplifyRapid App Development with AWS Amplify
Rapid App Development with AWS AmplifyRiza Fahmi
 
Menguak Misteri Module Bundler
Menguak Misteri Module BundlerMenguak Misteri Module Bundler
Menguak Misteri Module BundlerRiza Fahmi
 
Beberapa Web API Menarik
Beberapa Web API MenarikBeberapa Web API Menarik
Beberapa Web API MenarikRiza Fahmi
 
MVP development from software developer perspective
MVP development from software developer perspectiveMVP development from software developer perspective
MVP development from software developer perspectiveRiza Fahmi
 
Ekosistem JavaScript di Indonesia
Ekosistem JavaScript di IndonesiaEkosistem JavaScript di Indonesia
Ekosistem JavaScript di IndonesiaRiza Fahmi
 
Perkenalan ReasonML
Perkenalan ReasonMLPerkenalan ReasonML
Perkenalan ReasonMLRiza Fahmi
 
How I Generate Idea
How I Generate IdeaHow I Generate Idea
How I Generate IdeaRiza Fahmi
 
Strategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop SlideStrategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop SlideRiza Fahmi
 
Lesson Learned from Prolific Developers
Lesson Learned from Prolific DevelopersLesson Learned from Prolific Developers
Lesson Learned from Prolific DevelopersRiza Fahmi
 
Clean Code JavaScript
Clean Code JavaScriptClean Code JavaScript
Clean Code JavaScriptRiza Fahmi
 
The Future of AI
The Future of AIThe Future of AI
The Future of AIRiza Fahmi
 
Chrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take AwaysChrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take AwaysRiza Fahmi
 
Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6Riza Fahmi
 
Modern Static Site with GatsbyJS
Modern Static Site with GatsbyJSModern Static Site with GatsbyJS
Modern Static Site with GatsbyJSRiza Fahmi
 
Introduction to ReasonML
Introduction to ReasonMLIntroduction to ReasonML
Introduction to ReasonMLRiza Fahmi
 

Plus de Riza Fahmi (20)

Membangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan PhoenixMembangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan Phoenix
 
Berbagai Pilihan Karir Developer
Berbagai Pilihan Karir DeveloperBerbagai Pilihan Karir Developer
Berbagai Pilihan Karir Developer
 
Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020
 
Remote Working/Learning
Remote Working/LearningRemote Working/Learning
Remote Working/Learning
 
How to learn programming
How to learn programmingHow to learn programming
How to learn programming
 
Rapid App Development with AWS Amplify
Rapid App Development with AWS AmplifyRapid App Development with AWS Amplify
Rapid App Development with AWS Amplify
 
Menguak Misteri Module Bundler
Menguak Misteri Module BundlerMenguak Misteri Module Bundler
Menguak Misteri Module Bundler
 
Beberapa Web API Menarik
Beberapa Web API MenarikBeberapa Web API Menarik
Beberapa Web API Menarik
 
MVP development from software developer perspective
MVP development from software developer perspectiveMVP development from software developer perspective
MVP development from software developer perspective
 
Ekosistem JavaScript di Indonesia
Ekosistem JavaScript di IndonesiaEkosistem JavaScript di Indonesia
Ekosistem JavaScript di Indonesia
 
Perkenalan ReasonML
Perkenalan ReasonMLPerkenalan ReasonML
Perkenalan ReasonML
 
How I Generate Idea
How I Generate IdeaHow I Generate Idea
How I Generate Idea
 
Strategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop SlideStrategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop Slide
 
Lesson Learned from Prolific Developers
Lesson Learned from Prolific DevelopersLesson Learned from Prolific Developers
Lesson Learned from Prolific Developers
 
Clean Code JavaScript
Clean Code JavaScriptClean Code JavaScript
Clean Code JavaScript
 
The Future of AI
The Future of AIThe Future of AI
The Future of AI
 
Chrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take AwaysChrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take Aways
 
Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6
 
Modern Static Site with GatsbyJS
Modern Static Site with GatsbyJSModern Static Site with GatsbyJS
Modern Static Site with GatsbyJS
 
Introduction to ReasonML
Introduction to ReasonMLIntroduction to ReasonML
Introduction to ReasonML
 

Dernier

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Dernier (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

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: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 }
  • 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 = "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
  • 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 = "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 }
  • 34.
  • 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 }