Professional Documents
Culture Documents
Berkley Socket
Berkley Socket
listen
Server primitives:
accept
send + receive
close
connect
Client primitives:
send + receive
close
BERKELEY SERVICE PRIMITIVES
Create socket
TCP CLIENT/SERVER
bind a port to the
socket
CLIENT
listen for incoming
Create socket
connections
accept an
connect to server's
incoming
port
connection
loop loop
close connection
TCP SERVER
Sequence of calls
close() shutdown
TCP CLIENT
Sequence of calls
close() Shutdown
SERVER SIDE SOCKET DETAILS
SERVER
Create socket
int socket(int domain, int type, int protocol)
sockfd = socket(PF_INET, SOCK_STREAM, 0);
bind a port to the int bind(int sockfd, struct sockaddr *server_addr, socklen_t length)
socket
bind(sockfd, &server, sizeof(server));
accept an
incoming
int accept(int sockfd, struct sockaddr *incoming_address, socklen_t length)
connection newfd = accept(sockfd, &client, sizeof(client)); /* BLOCKS */
read from the int read(int sockfd, void * buffer, size_t buffer_size)
connection
read(newfd, buffer, sizeof(buffer));
CLIENT
Create socket
int socket(int domain, int type, int protocol)
sockfd = socket(PF_INET, SOCK_STREAM, 0);
connect to Server int connect(int sockfd, struct sockaddr *server_address, socklen_t length)
socket
connect(sockfd, &server, sizeof(server));
read from the int read(int sockfd, void * buffer, size_t buffer_size)
connection
read(sockfd, buffer, sizeof(buffer));
TRANSPORT LAYER
Service Primitives
TCP
UD
ELEMENTS OF TRANSPORT PROTOCOLS (ETP)
Transport <> Data Link
Addressing
Establishing a connection
Releasing a connection
Flow control and buffering
Multiplexing
Crash recovery
ETP: TRANSPORT <> DATA LINK
Explicit addressing
Connection establishment
Potential existence of storage capacity in subnet
Dynamically varying number of connections
ETP: ADDRESSING
Connection scenario
ETP: ADDRESSING
Connection scenario
Host 2 (server)
Time-of-day server attaches itself to TSAP 1522
Host 1 (client)
Connect from TSAP 1208 to TSAP 1522
Setup network connection to host 2
Send transport connection request
Host 2
Accept connection request
ETP: ADDRESSING
Getting TSAP addresses?
Stable TSAP addresses
For key services
Not for user processes
active for a short time
number of addresses limited
Name servers
to find existing servers
map service name into TSAP address
Initial connection protocol
ETP: ADDRESSING