Java_Socket_Programming (2).ppt

JAVA Socket Programming
Source: by Joonbok Lee, KAIST, 2003
What is a socket?
• Socket
– The combination of an IP address and a port number.
– The name of the Berkeley-derived application programming
interfaces (APIs) for applications using TCP/IP protocols.
– Two types
• Stream socket : reliable two-way connected communication streams
• Datagram socket
• Socket pair
– Specified the two end points that uniquely identifies each TCP
connection in an internet.
– 4-tuple: (client IP address, client port number, server IP address,
server port number)
Sockets for server and client
• Server
– Welcoming socket
• Welcomes some initial contact from a client.
– Connection socket
• Is created at initial contact of client.
• New socket that is dedicated to the particular client.
• Client
– Client socket
• Initiate a TCP connection to the server by creating a socket
object. (Three-way handshake)
• Specify the address of the server process, namely, the IP
address of the server and the port number of the process.
Socket functional calls
• socket (): Create a socket
• bind(): bind a socket to a local IP address and port #
• listen(): passively waiting for connections
• connect(): initiating connection to another socket
• accept(): accept a new connection
• Write(): write data to a socket
• Read(): read data from a socket
• sendto(): send a datagram to another UDP socket
• recvfrom(): read a datagram from a UDP socket
• close(): close a socket (tear down the connection)
Sockets
Socket-programming using TCP
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
process
TCP with
buffers,
variables
socket
internet
client
server
socket( )
bind( )
connect( )
socket( )
bind( )
listen( )
accept( )
send( )
recv( )
close( ) close( )
recv( )
send( )
TCP conn. request
TCP ACK
Socket programming with TCP
Example client-server app:
• client reads line from standard
input (inFromUser stream) ,
sends to server via socket
(outToServer stream)
• server reads line from socket
• server converts line to
uppercase, sends back to client
• client reads, prints modified
line from socket
(inFromServer stream)
outToServer
to network from network
inFromServer
inFromUser
keyboard monitor
Process
clientSocket
input
stream
input
stream
output
stream
TCP
socket
Input stream:
sequence of bytes
into process
output stream:
sequence of bytes
out of process
Client
process
client TCP
socket
Client/server socket interaction: TCP
wait for incoming
connection request
connectionSocket =
welcomeSocket.accept()
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
create socket,
connect to hostid, port=x
clientSocket =
Socket()
close
connectionSocket
read reply from
clientSocket
close
clientSocket
Server (running on hostid) Client
send request using
clientSocket
read request from
connectionSocket
write reply to
connectionSocket
TCP
connection setup
1 sur 8

Recommandé

Java_Socket_Programming (2).ppt par
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptssuserec53e73
10 vues14 diapositives
Socket programming par
Socket programmingSocket programming
Socket programmingchandramouligunnemeda
10.3K vues30 diapositives
Socket programming in C par
Socket programming in CSocket programming in C
Socket programming in CDeepak Swain
1.1K vues11 diapositives
java networking par
 java networking java networking
java networkingWaheed Warraich
2.1K vues33 diapositives
Socket programming par
Socket programmingSocket programming
Socket programmingUjjwal Kumar
2.2K vues17 diapositives
Socket Programming_theory.ppt par
Socket Programming_theory.pptSocket Programming_theory.ppt
Socket Programming_theory.pptmdrobinhossain4
49 vues10 diapositives

Contenu connexe

Similaire à Java_Socket_Programming (2).ppt

Socket programming using C par
Socket programming using CSocket programming using C
Socket programming using CAjit Nayak
1.7K vues27 diapositives
Socket programming par
Socket programmingSocket programming
Socket programmingDivya Sharma
891 vues15 diapositives
Java 1 par
Java 1Java 1
Java 1VidyaVarshini3
24 vues17 diapositives
Lecture set 7 par
Lecture set 7Lecture set 7
Lecture set 7Gopi Saiteja
1.3K vues52 diapositives
Socket Programming par
Socket ProgrammingSocket Programming
Socket Programmingelliando dias
2K vues20 diapositives
Socket programming using java par
Socket programming using javaSocket programming using java
Socket programming using javaUC San Diego
5.7K vues23 diapositives

Similaire à Java_Socket_Programming (2).ppt(20)

Plus de ssuserec53e73

Enumeration.pptx par
Enumeration.pptxEnumeration.pptx
Enumeration.pptxssuserec53e73
1 vue10 diapositives
footscan.PPT par
footscan.PPTfootscan.PPT
footscan.PPTssuserec53e73
7 vues8 diapositives
UNIT II.pptx par
UNIT II.pptxUNIT II.pptx
UNIT II.pptxssuserec53e73
11 vues55 diapositives
Unit 1 iot.pptx par
Unit 1 iot.pptxUnit 1 iot.pptx
Unit 1 iot.pptxssuserec53e73
6 vues34 diapositives
IoT Reference Architecture.pptx par
IoT Reference Architecture.pptxIoT Reference Architecture.pptx
IoT Reference Architecture.pptxssuserec53e73
11 vues9 diapositives
patent ppt.pptx par
patent ppt.pptxpatent ppt.pptx
patent ppt.pptxssuserec53e73
2 vues8 diapositives

Plus de ssuserec53e73(20)

Introduction to measurement.pptx par ssuserec53e73
Introduction to measurement.pptxIntroduction to measurement.pptx
Introduction to measurement.pptx
ssuserec53e7316 vues

Dernier

Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption... par
Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption...Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption...
Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption...BC Chew
40 vues47 diapositives
PRELIMS ANSWER.pptx par
PRELIMS ANSWER.pptxPRELIMS ANSWER.pptx
PRELIMS ANSWER.pptxsouravkrpodder
56 vues60 diapositives
Introduction to AERO Supply Chain - #BEAERO Trainning program par
Introduction to AERO Supply Chain  - #BEAERO Trainning programIntroduction to AERO Supply Chain  - #BEAERO Trainning program
Introduction to AERO Supply Chain - #BEAERO Trainning programGuennoun Wajih
135 vues78 diapositives
Interaction of microorganisms with vascular plants.pptx par
Interaction of microorganisms with vascular plants.pptxInteraction of microorganisms with vascular plants.pptx
Interaction of microorganisms with vascular plants.pptxMicrobiologyMicro
75 vues33 diapositives
UNIT NO 13 ORGANISMS AND POPULATION.pptx par
UNIT NO 13 ORGANISMS AND POPULATION.pptxUNIT NO 13 ORGANISMS AND POPULATION.pptx
UNIT NO 13 ORGANISMS AND POPULATION.pptxMadhuri Bhande
48 vues33 diapositives
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab... par
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...RAHUL PAL
45 vues26 diapositives

Dernier(20)

Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption... par BC Chew
Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption...Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption...
Artificial Intelligence and The Sustainable Development Goals (SDGs) Adoption...
BC Chew40 vues
Introduction to AERO Supply Chain - #BEAERO Trainning program par Guennoun Wajih
Introduction to AERO Supply Chain  - #BEAERO Trainning programIntroduction to AERO Supply Chain  - #BEAERO Trainning program
Introduction to AERO Supply Chain - #BEAERO Trainning program
Guennoun Wajih135 vues
Interaction of microorganisms with vascular plants.pptx par MicrobiologyMicro
Interaction of microorganisms with vascular plants.pptxInteraction of microorganisms with vascular plants.pptx
Interaction of microorganisms with vascular plants.pptx
UNIT NO 13 ORGANISMS AND POPULATION.pptx par Madhuri Bhande
UNIT NO 13 ORGANISMS AND POPULATION.pptxUNIT NO 13 ORGANISMS AND POPULATION.pptx
UNIT NO 13 ORGANISMS AND POPULATION.pptx
Madhuri Bhande48 vues
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab... par RAHUL PAL
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...
RAHUL PAL45 vues
JRN 362 - Lecture Twenty-Two par Rich Hanley
JRN 362 - Lecture Twenty-TwoJRN 362 - Lecture Twenty-Two
JRN 362 - Lecture Twenty-Two
Rich Hanley39 vues
OOPs - JAVA Quick Reference.pdf par ArthyR3
OOPs - JAVA Quick Reference.pdfOOPs - JAVA Quick Reference.pdf
OOPs - JAVA Quick Reference.pdf
ArthyR376 vues
What is Digital Transformation? par Mark Brown
What is Digital Transformation?What is Digital Transformation?
What is Digital Transformation?
Mark Brown46 vues
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx par Niranjan Chavan
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptxGuidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx
Niranjan Chavan43 vues
GSoC 2024 .pdf par ShabNaz2
GSoC 2024 .pdfGSoC 2024 .pdf
GSoC 2024 .pdf
ShabNaz245 vues
Boston In The American Revolution par Mary Brown
Boston In The American RevolutionBoston In The American Revolution
Boston In The American Revolution
Mary Brown38 vues

Java_Socket_Programming (2).ppt

  • 1. JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003
  • 2. What is a socket? • Socket – The combination of an IP address and a port number. – The name of the Berkeley-derived application programming interfaces (APIs) for applications using TCP/IP protocols. – Two types • Stream socket : reliable two-way connected communication streams • Datagram socket • Socket pair – Specified the two end points that uniquely identifies each TCP connection in an internet. – 4-tuple: (client IP address, client port number, server IP address, server port number)
  • 3. Sockets for server and client • Server – Welcoming socket • Welcomes some initial contact from a client. – Connection socket • Is created at initial contact of client. • New socket that is dedicated to the particular client. • Client – Client socket • Initiate a TCP connection to the server by creating a socket object. (Three-way handshake) • Specify the address of the server process, namely, the IP address of the server and the port number of the process.
  • 4. Socket functional calls • socket (): Create a socket • bind(): bind a socket to a local IP address and port # • listen(): passively waiting for connections • connect(): initiating connection to another socket • accept(): accept a new connection • Write(): write data to a socket • Read(): read data from a socket • sendto(): send a datagram to another UDP socket • recvfrom(): read a datagram from a UDP socket • close(): close a socket (tear down the connection)
  • 6. Socket-programming using TCP process TCP with buffers, variables socket controlled by application developer controlled by operating system process TCP with buffers, variables socket internet client server socket( ) bind( ) connect( ) socket( ) bind( ) listen( ) accept( ) send( ) recv( ) close( ) close( ) recv( ) send( ) TCP conn. request TCP ACK
  • 7. Socket programming with TCP Example client-server app: • client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) • server reads line from socket • server converts line to uppercase, sends back to client • client reads, prints modified line from socket (inFromServer stream) outToServer to network from network inFromServer inFromUser keyboard monitor Process clientSocket input stream input stream output stream TCP socket Input stream: sequence of bytes into process output stream: sequence of bytes out of process Client process client TCP socket
  • 8. Client/server socket interaction: TCP wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket, port=x, for incoming request: welcomeSocket = ServerSocket() create socket, connect to hostid, port=x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server (running on hostid) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup