A TCP/IP socket is a bi-directional stream between two services.
Server Client -------- -------- socket socket bind listen accept --------- connect | recv* <-------- send* | send* --------> recv* | close --------- close close
- socket
- Gets socket resources (file descriptor, buffers).
- Specifies the protocol family.
- bind
- Gives the socket a local address (port, IP address).
- listen
- Establish that this socket will be a server socket (a/k/a a welcome socket) for accepting incoming connections.
- Sets the length of the listen queue (the maximum number of waiting incoming connections).
- accept
- Receive an incoming connection.
- Returns a new socket connected to the client.
- connect
- Connect a client socket to a remote host.
- send / recv
- Send and receive data over the connected socket stream.
- close
- Close the socket.
See: Beej's Networking Guide (especially sections 4 and 5).