TH4 Socket System Calls
Client side
Socket: creates socket descriptor
Connect: connects to remote peer (also finds local port number automatically)
Write: send outgoing data across the connection
Read: acquire incoming data from the connection
Close: terminate connection and de-allocate descriptor
Server side
Socket: creates socket descriptor
Bind: binds local IP address and port number passed in sockaddr_in structure
Listen: put socket in passive mode and set max number of simultaneous connections
Accept: accept the next incoming data from the connection
Read: acquire incoming data from the connection
Write: send outgoing dara across the connection
Close: terminate connection and de-allocate descriptor.
Summary of socket system calls
Socket()
- protocol family (e.g. PF_NET)
- protocol type of service (stream or datagram)
- creates socket descriptor
connect()
- remote endpoint address (of server)
- connects to remote peer (also finds local port number automatically)
write()
- descriptor of socket
- address of data to be sent
- length of data
- Writes data across connection. Call to write fails if previous data has not yet been completely written.
Read(0
- descriptor of socket
- address of data to be sent
- length of buffer
- extracts data which have arrived to the socket and places them into the buffer
close
- de-allocates the socket
bind()
- socket descriptor
- endpoint address (for TCPIP sockaddr_in structure)
- to specify an endpoint address for a socket (of the server)
listen()
- socket descriptor
- how many max connections simultaneously
- connection oriented servers use this to put the socket into passive mode
accept()
- a socket from which the next connection is accepted
- server uses this call to extract the next incoming connection. Accept creates a new socket for each new connection request and returns the socket descriptor to its caller. The server uses a new socket only for the new connection; it uses its original socket to accept additional connection requests.
User datagram services (UDP)
Recv: receive the next incoming datagram
Recvmsg: receive the next incoming datagram (variation of recv)
Recvfrom: receive the next incoming datagram and record its source endpoint address.
Send: send an outgoing datagram
Sendmsg: send an outgoing datagram (variation of send)
Sendto: sends an outgoing datagram to A pre-recorded endpoint address
Shutdown: terminate a TCP connection in one or both directories
Getpeername: after getting the connection obtain the remote machine’s endpoint address from the socket
Getsockopt: obtain the current options for the socket
Setsockopt: change the options for the socket.
Welcome to Kaizenlog.com If you're new here, you may want to subscribe to my RSS feed , Twitter You can contact us by using the contact form or submitting a comment. You can also share this post with your friends by clicking on the 'ShareThis' button above. Thanks for visiting!
Print This Post









Entries (RSS)