SlideShare a Scribd company logo
1 of 45
Download to read offline
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!

More Related Content

What's hot

Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1
rameshvvv
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
elliando dias
 
Hibernate Import.Sql I18n
Hibernate Import.Sql I18nHibernate Import.Sql I18n
Hibernate Import.Sql I18n
yifi2009
 
Scalable Socket Server by Aryo
Scalable Socket Server by AryoScalable Socket Server by Aryo
Scalable Socket Server by Aryo
Agate Studio
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
Anung Ariwibowo
 

What's hot (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 集群内部
 

Viewers also liked

Viewers also liked (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
 

Similar to Mobile Programming - Network Universitas Budi Luhur

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
hendriciraida
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
trilestari08
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
knight1128
 
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
hendriciraida
 

Similar to 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
 

More from Riza Fahmi

More from 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
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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 }