Professional Documents
Culture Documents
Application
Sockets
host or server
process socket
sending process shoves message out door sending process relies on transport infrastructure on other side of door which brings message to socket at receiving process
Internet
recv()
send()
close()
The socket API is protocol independent It can support several different communication domains domain parameter
AF_INET (internet) AF_LOCAL (or AF_UNIX) domain SOCK_STREAM SOCK_DGRAM SOCK_RAW (access IP packet) In the TCP/IP, the parameter is set to zero
5
protocol field indicates which protocol should be used with the socket
Demultiplexing
application application application application
ICMP
IGMP
TCP
UDP
ARP
IP Ethernet
RARP
incoming frame
6
Specify local IP address and local port for a socket Can use INADDR_ANY for any IP address when the host is multi-home host s parameter
Socket descriptor
*name and namelen parameters are used to supply the port and IP address of the local AP
*name points to the socket address data structure namelen indicate the length of socket address data structure
7
The sockaddr interface uses data abstraction. Thus, while the protocol domain may change, the interface remain the same
Struct sockaddr_in{ sa_family_t unsigned short int structin_addr unsigned char }; sin_family; sin_port; sin_addr; _pad[ ]
Sa_family and sin_family are common between the two structures The domain type in the socket() function must be the same value as the family.
8
Used to establish the connection *peer parameter specifies servers address and port number Used by client
Used in connection-oriented TCP: Forms a TCP connection, server uses accept to receive the call Used in connectionless UDP: record the servers address in the socket.
9
Transfer outgoing data from application send () is used in the socket which is connected sendto() and sendmsg() use to send a message using an unconnected socket
Perform the same operation as sendto, but abbreviates the arguments by defining a structure
Flags
MSG_OOB
Cause urgent data to be sent or read Peek at incoming data without removing it from the receive buffer Cause the kernel to bypass the normal routing function
10
MSG_PEEK MSG_DONTROUTE
Recv, recvfrom, and recvmsg Transfer incoming data to application recv() uses to receive data from a connected socket recvfrom() and recvmsg() is used to receive data from unconnected socket, receive data from arbitrary set of clients Read and write with sockets such as read and write for I/O
11
12
recv()
send()
close()
14
Used by server, TCP is in passive mode, UDP server dont require Prepares socket to accept incoming connections backlog parameter is the length of the server request queue (connection request queue)
15
Used by TCP server Waits for next connection establish and returns new socket Use the newsock to communication with this client Returns the address of the new connections peer in the sockaddr_in structure pointed to by *addr
16
17
18