SlideShare a Scribd company logo
CS3135/CS2135
Object Oriented Programming (Java)
BSCS-3 / MCS-3
Lecture # 24
Network Programming
Part-1
Java Network Programming
• Network Programming refers to writing programs that execute across multiple devices (computers),
in which the devices are all connected to each other using a network.
• IP address is a unique number assigned to a node of a network e.g. 192.168.0.1 . It is composed of
octets that range from 0 to 255. It is a logical address that can be changed.
• Protocol is a set of rules basically that is followed for communication. For example:
• TCP, FTP, Telnet, SMTP, POP etc.
• Port Number is used to uniquely identify different applications. It acts as a communication endpoint
between applications.
• The port number is associated with the IP address for communication between two applications.
• In connection-oriented protocol, acknowledgement is sent by the receiver. So it is reliable but slow.
The example of connection-oriented protocol is TCP.
• In connection-less protocol, acknowledgement is not sent by the receiver. So it is not reliable but
fast. The example of connection-less protocol is UDP.
• Socket is an endpoint between two way communication.
Instructor: Tanzila Kehkashan
2
Socket Programming
• Java Socket programming can be of two types:
• Connection-oriented uses classes Socket and ServerSocket
• Connection-less.uses classes DatagramSocket and DatagramPacket
• The client in socket programming must know two information.
• IP Address of Server, and Port number.
java.net.Socket
• Socket class can be used to create a socket and to connect to a remote host.
• Socket(String, int) //host, port
• InputStream getInputStream() //returns the InputStream attached with current socket object.
• OutputStream getOutputStream() //returns the OutputStream attached with curent socket object.
• synchronized void close() //closes this socket
Instructor: Tanzila Kehkashan
3
Socket Programming
java.net.ServerSocket
• The ServerSocket class can be used to create a server socket. This object is used to accept
connections from client sockets.
• ServerSocket(int) //port
• Socket accept() //returns the socket and establish a connection between server and client.
• synchronized void close() //closes the server socket.
Instructor: Tanzila Kehkashan
4
• Run two instances of Command Prompt.
• Run server file first.
Instructor: Tanzila Kehkashan
5
• Both server and client communicates
Instructor: Tanzila Kehkashan
6
Instructor: Tanzila Kehkashan
7

More Related Content

Similar to OOP Lecture 24-Network Programming-Part1.pptx (20)

PPTX
Networking in Java
Tushar B Kute
 
PPT
Unit 8 Java
arnold 7490
 
PPTX
#1 (TCPvs. UDP)
Ghadeer AlHasan
 
PPT
Network Programming in Java
Tushar B Kute
 
PPT
Advanced Java Topics
Salahaddin University-Erbil
 
PPT
Network programming in Java
Tushar B Kute
 
PPTX
Java networking
ssuser3a47cb
 
PDF
JavaSockets-Session10 New York university.pdf
jose19881
 
PPT
Network programming in Java
Tushar B Kute
 
PDF
28 networking
Ravindra Rathore
 
PPTX
Network programming in java - PPT
kamal kotecha
 
PDF
Chap 1 Network Theory & Java Overview
Ministry of Higher Education
 
PPTX
Java socket programming
Mohammed Abdalla Youssif
 
PDF
Socket Programming by Rajkumar Buyya
iDhawalVaja
 
PPTX
Java seminar.pptx
shirindigitel
 
PPTX
Advance Java-Network Programming
ashok hirpara
 
PDF
Java Programming - 07 java networking
Danairat Thanabodithammachari
 
PPTX
Socket programming
Ujjwal Kumar
 
PDF
Networking Basics1ofjavaprogramming.pptx.pdf
omkarthombare4989
 
PPTX
Socket & Server Socket
Hemant Chetwani
 
Networking in Java
Tushar B Kute
 
Unit 8 Java
arnold 7490
 
#1 (TCPvs. UDP)
Ghadeer AlHasan
 
Network Programming in Java
Tushar B Kute
 
Advanced Java Topics
Salahaddin University-Erbil
 
Network programming in Java
Tushar B Kute
 
Java networking
ssuser3a47cb
 
JavaSockets-Session10 New York university.pdf
jose19881
 
Network programming in Java
Tushar B Kute
 
28 networking
Ravindra Rathore
 
Network programming in java - PPT
kamal kotecha
 
Chap 1 Network Theory & Java Overview
Ministry of Higher Education
 
Java socket programming
Mohammed Abdalla Youssif
 
Socket Programming by Rajkumar Buyya
iDhawalVaja
 
Java seminar.pptx
shirindigitel
 
Advance Java-Network Programming
ashok hirpara
 
Java Programming - 07 java networking
Danairat Thanabodithammachari
 
Socket programming
Ujjwal Kumar
 
Networking Basics1ofjavaprogramming.pptx.pdf
omkarthombare4989
 
Socket & Server Socket
Hemant Chetwani
 

More from Tanzila Kehkashan (20)

PPTX
OOP Lecture 25-Network Programming-Part2.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 23-JAR Files.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 22-JApplet.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 21-Graphics, Audio.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 20-MultiThreading.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 19-JMenuBar.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 18-DB Connectivity-Part2.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 17-DB Connectivity-Part1.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 16-Math,Timer.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 15-FileHandling,JFileChooser.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 14-ExceptionHandling.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 13-Color,Font,ImageIcon.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 12-EventHandling2.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 11-EventHandling1.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 10-JTable,JTabbedPane,LayoutManagers.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 9-JComboBox,JList,JPanel.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 8-JCheckBox,JRadioButton,JProgressBar.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 7-JTextField,JTextArea,JPassword,JButton.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 6-JFrame,JScrollPane,JLabel.pptx
Tanzila Kehkashan
 
PPTX
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
Tanzila Kehkashan
 
OOP Lecture 25-Network Programming-Part2.pptx
Tanzila Kehkashan
 
OOP Lecture 23-JAR Files.pptx
Tanzila Kehkashan
 
OOP Lecture 22-JApplet.pptx
Tanzila Kehkashan
 
OOP Lecture 21-Graphics, Audio.pptx
Tanzila Kehkashan
 
OOP Lecture 20-MultiThreading.pptx
Tanzila Kehkashan
 
OOP Lecture 19-JMenuBar.pptx
Tanzila Kehkashan
 
OOP Lecture 18-DB Connectivity-Part2.pptx
Tanzila Kehkashan
 
OOP Lecture 17-DB Connectivity-Part1.pptx
Tanzila Kehkashan
 
OOP Lecture 16-Math,Timer.pptx
Tanzila Kehkashan
 
OOP Lecture 15-FileHandling,JFileChooser.pptx
Tanzila Kehkashan
 
OOP Lecture 14-ExceptionHandling.pptx
Tanzila Kehkashan
 
OOP Lecture 13-Color,Font,ImageIcon.pptx
Tanzila Kehkashan
 
OOP Lecture 12-EventHandling2.pptx
Tanzila Kehkashan
 
OOP Lecture 11-EventHandling1.pptx
Tanzila Kehkashan
 
OOP Lecture 10-JTable,JTabbedPane,LayoutManagers.pptx
Tanzila Kehkashan
 
OOP Lecture 9-JComboBox,JList,JPanel.pptx
Tanzila Kehkashan
 
OOP Lecture 8-JCheckBox,JRadioButton,JProgressBar.pptx
Tanzila Kehkashan
 
OOP Lecture 7-JTextField,JTextArea,JPassword,JButton.pptx
Tanzila Kehkashan
 
OOP Lecture 6-JFrame,JScrollPane,JLabel.pptx
Tanzila Kehkashan
 
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
Tanzila Kehkashan
 
Ad

Recently uploaded (20)

PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Ad

OOP Lecture 24-Network Programming-Part1.pptx

  • 1. CS3135/CS2135 Object Oriented Programming (Java) BSCS-3 / MCS-3 Lecture # 24 Network Programming Part-1
  • 2. Java Network Programming • Network Programming refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network. • IP address is a unique number assigned to a node of a network e.g. 192.168.0.1 . It is composed of octets that range from 0 to 255. It is a logical address that can be changed. • Protocol is a set of rules basically that is followed for communication. For example: • TCP, FTP, Telnet, SMTP, POP etc. • Port Number is used to uniquely identify different applications. It acts as a communication endpoint between applications. • The port number is associated with the IP address for communication between two applications. • In connection-oriented protocol, acknowledgement is sent by the receiver. So it is reliable but slow. The example of connection-oriented protocol is TCP. • In connection-less protocol, acknowledgement is not sent by the receiver. So it is not reliable but fast. The example of connection-less protocol is UDP. • Socket is an endpoint between two way communication. Instructor: Tanzila Kehkashan 2
  • 3. Socket Programming • Java Socket programming can be of two types: • Connection-oriented uses classes Socket and ServerSocket • Connection-less.uses classes DatagramSocket and DatagramPacket • The client in socket programming must know two information. • IP Address of Server, and Port number. java.net.Socket • Socket class can be used to create a socket and to connect to a remote host. • Socket(String, int) //host, port • InputStream getInputStream() //returns the InputStream attached with current socket object. • OutputStream getOutputStream() //returns the OutputStream attached with curent socket object. • synchronized void close() //closes this socket Instructor: Tanzila Kehkashan 3
  • 4. Socket Programming java.net.ServerSocket • The ServerSocket class can be used to create a server socket. This object is used to accept connections from client sockets. • ServerSocket(int) //port • Socket accept() //returns the socket and establish a connection between server and client. • synchronized void close() //closes the server socket. Instructor: Tanzila Kehkashan 4
  • 5. • Run two instances of Command Prompt. • Run server file first. Instructor: Tanzila Kehkashan 5
  • 6. • Both server and client communicates Instructor: Tanzila Kehkashan 6