Socket Presentation
-
Upload
yogananda-patnaik -
Category
Documents
-
view
222 -
download
0
Transcript of Socket Presentation
-
7/31/2019 Socket Presentation
1/13
SOCKETS
1
-
7/31/2019 Socket Presentation
2/13
COMPUTER NETWORK
A computer networkis aninterconnected collection of autonomouscomputers.
-
7/31/2019 Socket Presentation
3/13
WHAT A NETWORK INCLUDES
Address: byte-string that identifies a node usually unique
Routing: process of forwarding messages
to the destination node based on itsaddress.
Protocol: set of rules used forcommunication.
-
7/31/2019 Socket Presentation
4/13
BASIC PARADIGM FORCOMMUNICATION
Establish contact (connection).
Exchange information (bi-directional).
Terminate contact.
-
7/31/2019 Socket Presentation
5/13
ELEMENTS OF C-S COMPUTING
5
Network
Reque
st
R
esult
a client, a server, and network
ClientServer
Client machine
Server machine
-
7/31/2019 Socket Presentation
6/13
CLIENT-SERVER COMMUNICATION
Client sends a request to the server
Server accepts the request and establish a connection
-
7/31/2019 Socket Presentation
7/13
SOCKETS
A socket is defined as an endpoint forcommunication.
Concatenation of IP address and port
A socket pair (local IP address, local port,foreign IP address, foreign port) uniquely
identifies a communication.
The socket 161.25.19.8:1625 refers to port1625 on host 161.25.19.8
-
7/31/2019 Socket Presentation
8/13
TWO ESSENTIAL TYPES OF SOCKETS
SOCK_STREAM
TCP reliable delivery
in-order guaranteed
connection-oriented
Bidirectional Stream flow of data
SOCK_DGRAM
UDP
unreliable delivery
no order guarantees
no notion of connection
app indicates dest. foreach packet
can send or receive
Datagram format
App
socket3 2 1
Dest.
App
socket3 2 1
D1
D3
D2
-
7/31/2019 Socket Presentation
9/13
SOCKET FUNCTIONAL CALLS
socket (): Create a socket
bind(): bind a socket to a local IP address andport #
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)
-
7/31/2019 Socket Presentation
10/13
CONNECTION-ORIENTED EXAMPLE (TCP)
10
Server
Socket()
Bind()
Client
Socket()
Listen()
Accept()
Recv()
Send()
Connect()
Send()
Recv()
Block until
connect
Process
request
Connection Establishmt.
Data (request)
Data (reply)
Bind()
-
7/31/2019 Socket Presentation
11/13
CONNECTIONLESS EXAMPLE (UDP)
11
Server
Socket()
Bind()Client
Socket()
Recvfrom()
Sendto()
Bind()
Sendto()
Recvfrom()
Block until
Data from
client
Process
request
Data (request)
Data (reply)
-
7/31/2019 Socket Presentation
12/13
JAVA SOCKETS
12
ServerSocket(1254)
Socket(128.250.25.158, 1254)
Output/write stream
Input/read stream
It can be host_name like mandroo.cs.mu.oz.au
Client
server
-
7/31/2019 Socket Presentation
13/13