Server socket

From Wikipedia, the free encyclopedia

A server socket is a computer communications end point for new incoming connections. The server socket accepts incoming connections, handles lower-level network traffic to finalize the connection and then forks a new connection for reading or writing. The server socket continues to be available to accept other incoming connections.

[edit] Pseudocode example

#Create a server socket
ServerSocket = CreateNewSocket( AF_INET, SOCK_STREAM );
BindSocketToIP( ServerSocket, LOCALIP );
ListenForConnections( ServerSocket );

#Accept incoming connections
While( TRUE ) {
   NewSocket = AcceptConnection( ServerSocket );
   While( Data = ReceiveData( NewSocket ) ) {
      ...
   }
}

AF_INET refers to the socket using a standard network protocol, in this case IPv4. SOCK_STREAM refers to the socket using a standard transport protocol, in this case TCP. See the article on Berkeley sockets for further information.