SlideShare a Scribd company logo
1 of 38
Download to read offline
Networking
Chapter - 27
Mrs. L. Priya
Head & Assit. Professor
Dept. of Comp. Sci.
Sri Kaliswari College
Sivakasi
Introduction
Manipulating URLs
Reading the Files on
the Server
Establishing Simple
Server Using Stream
Sockets
Datagrams:
Connectionless
Client/Server
Interaction
Topics to be covered
Introduction
Topics to be covered
•Built – in Networking Facilities – Easy to Program
•Classes and Interfaces declared in java.net package
•Packages for Stream Based Communications and Packet
based Communication.
•Focus on C/S relationship – client requests and server
responds
•Socket Based Communications – Read from a Socket and
Write to a socket.
Introduction
Introduction – Stream Sockets
•Data flows between process in continuous streams
•Connection Oriented Service
•Protocol used – TCP (Transmission Control Protocol)
Introduction – Datagram Sockets
•Individual Packets of Information are transmitted.
•Connection Less Service – does not guarantee that
packets arrive in any particular order (May be lost or
duplicated).
•Protocol used – UDP (User Datagram Protocol)
Manipulating
URLS
Topics to be covered
Manipulating URLs
•HTTP – Hyper Text Transfer Protocol – Forms the basis of
the web
•URI – Uniform Resource Identifiers – Identify data on the
internet
•URL – Uniform Resource Locator – Locations of websites
and webpages
Manipulating URLs
•showDocument method of AppletContext - Used to
display the webpage in Applet.
Manipulating URLs - Example
•<html> <body>
• <applet>
• <param name = "title0" value = "Java Home Page">
• <param name = "location0" value = “www.oracle.com/technetwork/java/">
• <param name = "title1" value = "Deitel">
• <param name = "location1" value = "http://www.deitel.com/">
• <param name = "title2" value = "JGuru">
• <param name = "location2" value = "http://www.jGuru.com/">
• <param name = "title3" value = "JavaWorld">
• <param name = "location3" value = "http://www.javaworld.com/">
• </applet>
•</body></html>
Manipulating URLs - Example
public class SiteSelector extends Japplet
{
public void init()
{ title = getParameter( "title0“ );
location = getParameter( "location0“);
try
{ URL url = new URL( location ); // convert location to URL
AppletContext browser = getAppletContext();
browser.showDocument(url);
} // end try
catch ( MalformedURLException urlException )
{ urlException.printStackTrace();
} // end catch
Reading a
File on a
Web Server
Topics to be covered
Reading a File on a Server
Swing GUI component JEditorPane - to display the
contents of a file on a webserver.
HyperLinkEvent – Event Raised when a user clicks a
Hyperlink
Reading a File on a Server
public class ReadServerFile extends JFrame
{
JEditorPane contentsArea;
public ReadServerFile()
{
contentsArea = new (); // create
contentsArea
contentsArea.setEditable( false );
contentsArea. (
new HyperlinkListener()
{
Reading a File on a Server
public void ( HyperlinkEvent event )
{
if ( event.getEventType() ==
)
{
location = .toString();
contentsArea. ( location ); ;
}
} // end method hyperlinkUpdate
} // end inner class
); // end call to addHyperlinkListener
}
}
Establishing
Simple
Server Using
Stream
Sockets
Topic to be covered
Establishing Simple Server Using
Stream Sockets
Step 1 : Create a ServerSocket
Step 2 : Wait for a Connection
Step 3 : Get the Socket’s I/O Streams
Step 4 : Perform the Processing
Step 5 : Close the Connection
STEP – 1 : Create a Server Socket
Call the ServerSocket constructor
ServerSocket server =
new ServerSocket(portnum,quelength)
Portnum  Registers available TCP port number
Quelength  Max. Number of Clients that can wait
This constructor establishes the port
where the server waits for connection
from clients 
STEP – 2 : Wait for a Connection
Program calls the ServerSocket method accept which returns a
Socket object
Socket connection = server.accept();
Socket object
 Connection with the client.
Allows the server to interact with the client.
STEP – 3 : Get the Sockets I/O Stream
Get the I/P and O/P stream for Communications.
Server sends information to client via OutputStream
calls the method getOutputStream to get the reference
Server receives information from the client via InputStream
calls the method getInputStream to get the reference
Methods write and read of Stream objects
send / receive individual /sequence of
bytes.
STEP – 3 : Get the Sockets I/O Stream
ObjectInputStream input =
new ObjectInputStream(connection.getInputStream());
ObjectOutputStream output =
new ObjectOutputStream(connection.getOutputStream());
STEP – 4 : Perform the Processing
Client and Server communicates via
InputStream and OutputStream
STEP – 5 : Close the Connection
Server closes the connection via close method
Establishing Simple Client Using
Stream Sockets
Step 1 : Create a Socket to connect to the Server
Step 2 : Get the Sockets I/O Streams
Step 3 : Perform the Processing
Step 4 : Close the Connection
STEP – 1 : Create a Server Socket
Create a Socket to connect to the server
IOException – raised, If the connection fails
UnknownHostException – raised, when the system unable
to resolve the server name
STEP – 2 : Get the Sockets I/O
Streams
Get the references of InputStream and OutputStream
Using Socket methods getInputStream and
getOutputStream
STEP – 3 : Perform the processing
Client and Server communicates via the InputStream and
OutputStream.
STEP – 4 : Close the Connection
Closes the connection when the transmission is complete
by invoking the close method.
Client / Server Interaction with Stream
socket connections -
java.io.*;
java.net.*;
javax.swing.*;
public class Server extends JFrame
{
private ObjectOutputStream output;
private ObjectInputStream input;
private ServerSocket server;
private Socket connection;
public Server()
{
server = new ServerSocket( 12345, 100 );
connection = server.accept();
Client / Server Interaction with Stream
socket connections -
output = new ObjectOutputStream( connection.getOutputStream() );
input = new ObjectInputStream( connection.getInputStream() );
String message = "Connection successful";
output.writeObject( "SERVER>>> " + message );
output.flush();
output.close();
input.close();
connection.close();
}
}
Client / Server Interaction with Stream
socket connections -
public class Client extends Jframe
{
JTextField txtField;
ObjectOutputStream output;
private ObjectInputStream input;
private String message = "";
private Socket client;
public Client( )
{
client = new Socket( InetAddress.getByName( “Node-23” ), 12345 );
client = new Socket( InetAddres.getLocalHost(), 12345 );
output = new ObjectOutputStream( client.getOutputStream() );
input = new ObjectInputStream( client.getInputStream() );
message = ( String ) input.readObject();
txtField.setText(message);
output.close(); // close output stream
input.close(); // close input stream
client.close();
Client / Server Interaction with Stream
socket connections -
message = ( String ) input.readObject();
txtField.setText(message);
output.close();
input.close();
client.close();
}
}
Datagrams:
Connectionless
Client/Server
Interaction
Topic to be covered
Datagrams : Connectionless Client/Server
Interaction
Connectionless Transmission
- like a mail is carried via the postal service.
- Message break into separate pieces and
sequentially numbered.
- Letters may arrive in order or not.
-Receiver reassembles the pieces into sequential
order
Protocol - UDP
Datagrams : Connectionless Client/Server
Interaction – SERVER class
DatagramPackets : Packets used to send and receive
information.
DatagramSocket : Sends and Receives the packets.
SocketException : if the DatagramSocket constructor fails
to bind to the port
Datagrams : Connectionless Client/Server
Interaction – SERVER class
import java.net.*;
import java.io.*;
import javax.swing.*;
public class Server extends JFrame
{ JTextArea txtarea;
public Server()
{
Txtarea = new JTextArea(10,40);
socket = new DatagramSocket( 5000 );
byte[] data = new byte[ 100 ]; // set up packet
DatagramPacket receivePacket =
new DatagramPacket( data, data.length );
Datagrams : Connectionless Client/Server
Interaction – SERVER class
socket.receive( receivePacket );
txtArea.setText( "nPacket received:" +
"nFrom host: " + receivePacket.getAddress() +
"nHost port: " + receivePacket.getPort() +
"nLength: " + receivePacket.getLength() +
"nContaining:nt" +
new String( receivePacket.getData(),
0, receivePacket.getLength() ) );
}
}
Datagrams : Connectionless Client/Server
Interaction – CLIENT class
import java.net.*;
import java.io.*;
import javax.swing.*;
public class Client extends JFrame
{
public Server()
{
String msg = “Welcome to Datagram”;
byte[] data = msg.getBytes();
DatagramPacket sendPacket = new DatagramPacket( data,
data.length, InetAddress.getLocalHost(), 5000 );
socket.send( sendPacket );
}
}

More Related Content

What's hot

Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1Aleh Struneuski
 
Asp.net server control
Asp.net  server controlAsp.net  server control
Asp.net server controlSireesh K
 
Distributed Web-Cache using OpenFlow
Distributed Web-Cache using OpenFlowDistributed Web-Cache using OpenFlow
Distributed Web-Cache using OpenFlowAasheesh Tandon
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theoryMukesh Tekwani
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddressSayak Sarkar
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik TambekarPratik Tambekar
 
Share pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShare pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShakir Majeed Khan
 
Android networking in Hindi
Android networking in Hindi Android networking in Hindi
Android networking in Hindi Vipin sharma
 
Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Sachin Katariya
 
21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboards21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboardsDenis Ristic
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 

What's hot (20)

Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1
 
Asp.net server control
Asp.net  server controlAsp.net  server control
Asp.net server control
 
Scmad Chapter09
Scmad Chapter09Scmad Chapter09
Scmad Chapter09
 
Java networking
Java networkingJava networking
Java networking
 
Apache Beam de A à Z
 Apache Beam de A à Z Apache Beam de A à Z
Apache Beam de A à Z
 
Distributed Web-Cache using OpenFlow
Distributed Web-Cache using OpenFlowDistributed Web-Cache using OpenFlow
Distributed Web-Cache using OpenFlow
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddress
 
Android Networking
Android NetworkingAndroid Networking
Android Networking
 
Le Wagon - Web 101
Le Wagon - Web 101Le Wagon - Web 101
Le Wagon - Web 101
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Share pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShare pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbs
 
Android networking in Hindi
Android networking in Hindi Android networking in Hindi
Android networking in Hindi
 
Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboards21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboards
 
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

Similar to Chapter 27 Networking - Deitel & Deitel

Networking
NetworkingNetworking
NetworkingTuan Ngo
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming ClientsAdil Jafri
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming ClientsAdil Jafri
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsYakov Fain
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
21servers And Applets
21servers And Applets21servers And Applets
21servers And AppletsAdil Jafri
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
CHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxCHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxDhrumilSheth3
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web SocketsFahad Golra
 
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
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
 

Similar to Chapter 27 Networking - Deitel & Deitel (20)

Sockets
SocketsSockets
Sockets
 
Networking
NetworkingNetworking
Networking
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming Clients
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming Clients
 
Java 1
Java 1Java 1
Java 1
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
Servlets
ServletsServlets
Servlets
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
21servers And Applets
21servers And Applets21servers And Applets
21servers And Applets
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
CHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxCHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptx
 
T2
T2T2
T2
 
java networking
 java networking java networking
java networking
 
Ipc
IpcIpc
Ipc
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
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
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

Chapter 27 Networking - Deitel & Deitel

  • 1. Networking Chapter - 27 Mrs. L. Priya Head & Assit. Professor Dept. of Comp. Sci. Sri Kaliswari College Sivakasi
  • 2. Introduction Manipulating URLs Reading the Files on the Server Establishing Simple Server Using Stream Sockets Datagrams: Connectionless Client/Server Interaction Topics to be covered
  • 4. •Built – in Networking Facilities – Easy to Program •Classes and Interfaces declared in java.net package •Packages for Stream Based Communications and Packet based Communication. •Focus on C/S relationship – client requests and server responds •Socket Based Communications – Read from a Socket and Write to a socket. Introduction
  • 5. Introduction – Stream Sockets •Data flows between process in continuous streams •Connection Oriented Service •Protocol used – TCP (Transmission Control Protocol)
  • 6. Introduction – Datagram Sockets •Individual Packets of Information are transmitted. •Connection Less Service – does not guarantee that packets arrive in any particular order (May be lost or duplicated). •Protocol used – UDP (User Datagram Protocol)
  • 8. Manipulating URLs •HTTP – Hyper Text Transfer Protocol – Forms the basis of the web •URI – Uniform Resource Identifiers – Identify data on the internet •URL – Uniform Resource Locator – Locations of websites and webpages
  • 9. Manipulating URLs •showDocument method of AppletContext - Used to display the webpage in Applet.
  • 10. Manipulating URLs - Example •<html> <body> • <applet> • <param name = "title0" value = "Java Home Page"> • <param name = "location0" value = “www.oracle.com/technetwork/java/"> • <param name = "title1" value = "Deitel"> • <param name = "location1" value = "http://www.deitel.com/"> • <param name = "title2" value = "JGuru"> • <param name = "location2" value = "http://www.jGuru.com/"> • <param name = "title3" value = "JavaWorld"> • <param name = "location3" value = "http://www.javaworld.com/"> • </applet> •</body></html>
  • 11. Manipulating URLs - Example public class SiteSelector extends Japplet { public void init() { title = getParameter( "title0“ ); location = getParameter( "location0“); try { URL url = new URL( location ); // convert location to URL AppletContext browser = getAppletContext(); browser.showDocument(url); } // end try catch ( MalformedURLException urlException ) { urlException.printStackTrace(); } // end catch
  • 12. Reading a File on a Web Server Topics to be covered
  • 13. Reading a File on a Server Swing GUI component JEditorPane - to display the contents of a file on a webserver. HyperLinkEvent – Event Raised when a user clicks a Hyperlink
  • 14. Reading a File on a Server public class ReadServerFile extends JFrame { JEditorPane contentsArea; public ReadServerFile() { contentsArea = new (); // create contentsArea contentsArea.setEditable( false ); contentsArea. ( new HyperlinkListener() {
  • 15. Reading a File on a Server public void ( HyperlinkEvent event ) { if ( event.getEventType() == ) { location = .toString(); contentsArea. ( location ); ; } } // end method hyperlinkUpdate } // end inner class ); // end call to addHyperlinkListener } }
  • 17. Establishing Simple Server Using Stream Sockets Step 1 : Create a ServerSocket Step 2 : Wait for a Connection Step 3 : Get the Socket’s I/O Streams Step 4 : Perform the Processing Step 5 : Close the Connection
  • 18. STEP – 1 : Create a Server Socket Call the ServerSocket constructor ServerSocket server = new ServerSocket(portnum,quelength) Portnum  Registers available TCP port number Quelength  Max. Number of Clients that can wait This constructor establishes the port where the server waits for connection from clients 
  • 19. STEP – 2 : Wait for a Connection Program calls the ServerSocket method accept which returns a Socket object Socket connection = server.accept(); Socket object  Connection with the client. Allows the server to interact with the client.
  • 20. STEP – 3 : Get the Sockets I/O Stream Get the I/P and O/P stream for Communications. Server sends information to client via OutputStream calls the method getOutputStream to get the reference Server receives information from the client via InputStream calls the method getInputStream to get the reference Methods write and read of Stream objects send / receive individual /sequence of bytes.
  • 21. STEP – 3 : Get the Sockets I/O Stream ObjectInputStream input = new ObjectInputStream(connection.getInputStream()); ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
  • 22. STEP – 4 : Perform the Processing Client and Server communicates via InputStream and OutputStream
  • 23. STEP – 5 : Close the Connection Server closes the connection via close method
  • 24. Establishing Simple Client Using Stream Sockets Step 1 : Create a Socket to connect to the Server Step 2 : Get the Sockets I/O Streams Step 3 : Perform the Processing Step 4 : Close the Connection
  • 25. STEP – 1 : Create a Server Socket Create a Socket to connect to the server IOException – raised, If the connection fails UnknownHostException – raised, when the system unable to resolve the server name
  • 26. STEP – 2 : Get the Sockets I/O Streams Get the references of InputStream and OutputStream Using Socket methods getInputStream and getOutputStream
  • 27. STEP – 3 : Perform the processing Client and Server communicates via the InputStream and OutputStream.
  • 28. STEP – 4 : Close the Connection Closes the connection when the transmission is complete by invoking the close method.
  • 29. Client / Server Interaction with Stream socket connections - java.io.*; java.net.*; javax.swing.*; public class Server extends JFrame { private ObjectOutputStream output; private ObjectInputStream input; private ServerSocket server; private Socket connection; public Server() { server = new ServerSocket( 12345, 100 ); connection = server.accept();
  • 30. Client / Server Interaction with Stream socket connections - output = new ObjectOutputStream( connection.getOutputStream() ); input = new ObjectInputStream( connection.getInputStream() ); String message = "Connection successful"; output.writeObject( "SERVER>>> " + message ); output.flush(); output.close(); input.close(); connection.close(); } }
  • 31. Client / Server Interaction with Stream socket connections - public class Client extends Jframe { JTextField txtField; ObjectOutputStream output; private ObjectInputStream input; private String message = ""; private Socket client; public Client( ) { client = new Socket( InetAddress.getByName( “Node-23” ), 12345 ); client = new Socket( InetAddres.getLocalHost(), 12345 ); output = new ObjectOutputStream( client.getOutputStream() ); input = new ObjectInputStream( client.getInputStream() ); message = ( String ) input.readObject(); txtField.setText(message); output.close(); // close output stream input.close(); // close input stream client.close();
  • 32. Client / Server Interaction with Stream socket connections - message = ( String ) input.readObject(); txtField.setText(message); output.close(); input.close(); client.close(); } }
  • 34. Datagrams : Connectionless Client/Server Interaction Connectionless Transmission - like a mail is carried via the postal service. - Message break into separate pieces and sequentially numbered. - Letters may arrive in order or not. -Receiver reassembles the pieces into sequential order Protocol - UDP
  • 35. Datagrams : Connectionless Client/Server Interaction – SERVER class DatagramPackets : Packets used to send and receive information. DatagramSocket : Sends and Receives the packets. SocketException : if the DatagramSocket constructor fails to bind to the port
  • 36. Datagrams : Connectionless Client/Server Interaction – SERVER class import java.net.*; import java.io.*; import javax.swing.*; public class Server extends JFrame { JTextArea txtarea; public Server() { Txtarea = new JTextArea(10,40); socket = new DatagramSocket( 5000 ); byte[] data = new byte[ 100 ]; // set up packet DatagramPacket receivePacket = new DatagramPacket( data, data.length );
  • 37. Datagrams : Connectionless Client/Server Interaction – SERVER class socket.receive( receivePacket ); txtArea.setText( "nPacket received:" + "nFrom host: " + receivePacket.getAddress() + "nHost port: " + receivePacket.getPort() + "nLength: " + receivePacket.getLength() + "nContaining:nt" + new String( receivePacket.getData(), 0, receivePacket.getLength() ) ); } }
  • 38. Datagrams : Connectionless Client/Server Interaction – CLIENT class import java.net.*; import java.io.*; import javax.swing.*; public class Client extends JFrame { public Server() { String msg = “Welcome to Datagram”; byte[] data = msg.getBytes(); DatagramPacket sendPacket = new DatagramPacket( data, data.length, InetAddress.getLocalHost(), 5000 ); socket.send( sendPacket ); } }