SlideShare a Scribd company logo
OpenLab 1
Socket Programming
openlabworld@gmail.com
OpenLab 2
Socket Programming
OpenLab 3
TCP/IP Beginning
OpenLab 4
TCP/IP ModelEncapsulation Decapsulation
OpenLab 5
Socket Description
OpenLab 6
Sockets
● Defination - An interface between an
application process and transport layer
– The application process can send/receive
messages to/from another application process
(local or remote)via a socket
● Types of Sockets
– TCP/Stream Socket
– UDP/Datagram Socket
– Raw Socket
● No Sockets – No communication
OpenLab 7
Socket Programming
using JAVA
● I/O Stream
● Reader/Writer
● Create Socket (Class)
– TCP Socket
● Server ServerSocket
● Client Socket
– UDP Socket
● DatagramSocket
OpenLab 8
I/O Stream
*https://docs.oracle.com/javase/tutorial/essential/io/streams.html
OutputStream
InputStream
Write
Read
- Input Source
- Output Destination
A stream can represent
many different kinds of
sources & destinations -
- Files
- Devices
- Programs
- Memory arrays
OpenLab 9
Classification of Streams
● Byte Stream
– Data in the form of individual bytes
● Text Strem
– Data as character of each 2 bytes
OpenLab 10
Byte Strem
● Byte Stream
– Data in the form of individual bytes
● InputStrem
– DataInputStream
– FileInputStream
– BufferedInputStream
– . . .
● OutputStream
– DataOutputStream
– FileOutputStream
– BufferedOutputStream
– . . .
OpenLab 11
Text Stream
● Text Stream
– Data as character of each 2 bytes
● Reader
– FileReader
– BufferedReader
● Writer
– FileWriter
– BufferedWriter
OpenLab 12
Steps to create
Socket(Server/Client)
● TCP Server Socket
– Step-1 Create ServerSocket Object
– Step-2 Wait for the client request
– Step-3 Create I/O streams for communication to the client.
– Step-4 Perform communication with client
– Step-5 Close Socket
● TCP Client Socket
– Step-1 Create Socket Object
– Step-2 Create I/O streams for communication with the server
– Step-3 Perform I/O or communication with the server
– Step-4 Close Socket
OpenLab 13
Create TCP Socket
(Connection Oriented)
socket()
connect()
bind()
accept()
send()
recv()
listen()
socket()
send()
recv()
Server Client
close() close()
OpenLab 14
Working of TCP Socket
OpenLab 15
Scenario 2
● Two BEST friends , they want to chat to each
using their computer and their fathers
uninstalled messanger from their computers
Ganesh
Mohan
OpenLab 16
Case-1
● They decided to create a STREAM/TCP Socket
● One way Communication
I/O Stream
Client Socket
MOHAN Server Socket
GANESH
`
OpenLab 17
Case-2
● They decided to create a STREAM/TCP Socket
● Two way Communication
I/O Stream
Client Socket
MOHAN Server Socket
GANESH
`
OpenLab 18
Steps to Create UDP Socket
● UDP Server/Client
– Step-1 Create DatagramSocket object
– Step-2 Create buffer for tmp storage
– Step-3 Store/Reterive data in/from buffer
– Step-4 Create DatagramPacket
– Step-5 send/receive DatagramPacket
OpenLab 19
Create UDP Socket
[Connection less]
socket()
bind()
recvfrom(
)
sendto()
socket()
recvfrom(
)
sendto()
ClientServer
close() close()
OpenLab 20
Case-1
● They decided to create a DATAGRAM/UDP
Socket
● One way Communication
Client Socket
MOHAN Server Socket
GANESH
Datagram Packet
OpenLab 21
Case-2
● They decided to create a DATAGRAM/UDP
Socket
● Two way Communication
Client Socket
MOHAN Server Socket
GANESH
Datagram Packet
Datagram Packet
OpenLab 22
To be continued...

More Related Content

What's hot (20)

Building blocks of android
Building blocks of android
Siddhesh Palkar
 
Html5 for mobiles
Html5 for mobiles
Christian Glahn
 
android menus
android menus
Deepa Rani
 
Remote invocation
Remote invocation
ishapadhy
 
모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)
Jongwon Kim
 
Data Abstraction
Data Abstraction
A. S. M. Shafi
 
Tcp/ip server sockets
Tcp/ip server sockets
rajshreemuthiah
 
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
Jongwon Kim
 
IOT Reference Model.doc
IOT Reference Model.doc
venui2
 
Android User Interface
Android User Interface
Shakib Hasan Sumon
 
Message and Stream Oriented Communication
Message and Stream Oriented Communication
Dilum Bandara
 
Java RMI Presentation
Java RMI Presentation
Masud Rahman
 
distributed shared memory
distributed shared memory
Ashish Kumar
 
WAP Technology
WAP Technology
vasanthimuniasamy
 
Web Application Testing
Web Application Testing
Richa Goel
 
Black Box Testing
Black Box Testing
Testbytes
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJB
Peter R. Egli
 
5.state diagrams
5.state diagrams
APU
 
Mobile Application Devlopement-Database connections-UNIT-5
Mobile Application Devlopement-Database connections-UNIT-5
Pallepati Vasavi
 
Test at Scale within your Internal Networks with BrowserStack Local Testing
Test at Scale within your Internal Networks with BrowserStack Local Testing
BrowserStack
 
Building blocks of android
Building blocks of android
Siddhesh Palkar
 
Remote invocation
Remote invocation
ishapadhy
 
모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)
Jongwon Kim
 
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
Jongwon Kim
 
IOT Reference Model.doc
IOT Reference Model.doc
venui2
 
Message and Stream Oriented Communication
Message and Stream Oriented Communication
Dilum Bandara
 
Java RMI Presentation
Java RMI Presentation
Masud Rahman
 
distributed shared memory
distributed shared memory
Ashish Kumar
 
Web Application Testing
Web Application Testing
Richa Goel
 
Black Box Testing
Black Box Testing
Testbytes
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJB
Peter R. Egli
 
5.state diagrams
5.state diagrams
APU
 
Mobile Application Devlopement-Database connections-UNIT-5
Mobile Application Devlopement-Database connections-UNIT-5
Pallepati Vasavi
 
Test at Scale within your Internal Networks with BrowserStack Local Testing
Test at Scale within your Internal Networks with BrowserStack Local Testing
BrowserStack
 

Viewers also liked (20)

Fundamental of Shell Programming
Fundamental of Shell Programming
Rahul Hada
 
Building Complex Topology using NS3
Building Complex Topology using NS3
Rahul Hada
 
NS3 Overview
NS3 Overview
Rahul Hada
 
1 session installation
1 session installation
Rahul Hada
 
Building Topology in NS3
Building Topology in NS3
Rahul Hada
 
Socket programming
Socket programming
chandramouligunnemeda
 
Support formobility
Support formobility
Rahul Hada
 
Software Engineering Introduction
Software Engineering Introduction
Rahul Hada
 
Risk
Risk
Rahul Hada
 
Inheritance
Inheritance
Rahul Hada
 
Risk
Risk
Rahul Hada
 
Introduction of Cloud Computing
Introduction of Cloud Computing
Rahul Hada
 
Socio-technical System
Socio-technical System
Rahul Hada
 
Mobile transportlayer
Mobile transportlayer
Rahul Hada
 
Tutorial ns 3-tutorial-slides
Tutorial ns 3-tutorial-slides
Vinayagam D
 
Ns3 implementation wifi
Ns3 implementation wifi
Salah Amean
 
ns-3 Tutorial
ns-3 Tutorial
mathieu_lacage
 
Quality planning
Quality planning
Rahul Hada
 
Introduction to Virtualization
Introduction to Virtualization
Rahul Hada
 
WLAN - IEEE 802.11
WLAN - IEEE 802.11
Rahul Hada
 
Fundamental of Shell Programming
Fundamental of Shell Programming
Rahul Hada
 
Building Complex Topology using NS3
Building Complex Topology using NS3
Rahul Hada
 
1 session installation
1 session installation
Rahul Hada
 
Building Topology in NS3
Building Topology in NS3
Rahul Hada
 
Support formobility
Support formobility
Rahul Hada
 
Software Engineering Introduction
Software Engineering Introduction
Rahul Hada
 
Introduction of Cloud Computing
Introduction of Cloud Computing
Rahul Hada
 
Socio-technical System
Socio-technical System
Rahul Hada
 
Mobile transportlayer
Mobile transportlayer
Rahul Hada
 
Tutorial ns 3-tutorial-slides
Tutorial ns 3-tutorial-slides
Vinayagam D
 
Ns3 implementation wifi
Ns3 implementation wifi
Salah Amean
 
Quality planning
Quality planning
Rahul Hada
 
Introduction to Virtualization
Introduction to Virtualization
Rahul Hada
 
WLAN - IEEE 802.11
WLAN - IEEE 802.11
Rahul Hada
 
Ad

Similar to Socket Programming using Java (20)

Socket Programming in Java.ppt yeh haii
Socket Programming in Java.ppt yeh haii
inambscs4508
 
Java socket programming
Java socket programming
Mohammed Abdalla Youssif
 
Networking in Python2025 (programs allll)
Networking in Python2025 (programs allll)
PriyankaPatil919748
 
Socket & Server Socket
Socket & Server Socket
Hemant Chetwani
 
How a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdf
arccreation001
 
Sockets
Sockets
sivindia
 
Java 1
Java 1
VidyaVarshini3
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
UC San Diego
 
Socket programming-tutorial-sk
Socket programming-tutorial-sk
sureshkarthick37
 
28 networking
28 networking
Ravindra Rathore
 
Network programming in Java
Network programming in Java
Tushar B Kute
 
NP-lab-manual.docx
NP-lab-manual.docx
RaviRajput416403
 
Networking in Java
Networking in Java
Tushar B Kute
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdf
RaviRajput416403
 
NP-lab-manual.pdf
NP-lab-manual.pdf
RaviRajput416403
 
Socket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
Introduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.ppt
MajedAboubennah
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
RockyBhai46825
 
Networking in java
Networking in java
shravan kumar upadhayay
 
JavaSockets-Session10 New York university.pdf
JavaSockets-Session10 New York university.pdf
jose19881
 
Socket Programming in Java.ppt yeh haii
Socket Programming in Java.ppt yeh haii
inambscs4508
 
Networking in Python2025 (programs allll)
Networking in Python2025 (programs allll)
PriyankaPatil919748
 
How a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdf
arccreation001
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
UC San Diego
 
Socket programming-tutorial-sk
Socket programming-tutorial-sk
sureshkarthick37
 
Network programming in Java
Network programming in Java
Tushar B Kute
 
Socket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
Introduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.ppt
MajedAboubennah
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
RockyBhai46825
 
JavaSockets-Session10 New York university.pdf
JavaSockets-Session10 New York university.pdf
jose19881
 
Ad

Recently uploaded (20)

Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 

Socket Programming using Java