Berkeley sockets API functions

by gowtham 2010-02-09 09:49:46

This list is a summary of functions or methods provided by the Berkeley sockets API library:

* socket() creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it.
* bind() is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address.
* listen() is used on the server side, and causes a bound TCP socket to enter listening state.
* connect() is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.
* accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.
* send() and recv(), or write() and read(), or sendto() and recvfrom(), are used for sending and receiving data to/from a remote socket.
* close() causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated.
* gethostbyname() and gethostbyaddr() are used to resolve host names and addresses.
* select() is used to prune a provided list of sockets for those that are: ready to read, ready to write or have errors
* poll() is used to check on the state of a socket. The socket can be tested to see if it can be written to, read from or has errors.
* getsockopt() is used to retrieve the current value of a particular socket option for the specified socket.
* setsockopt() is used to set a particular socket option for the specified socket.

Tagged in:


You must LOGIN to add comments