next up previous contents index
Next: Buffered, message-based communication. Up: Socket I/O Previous: Socket I/O   Contents   Index

General socket calls.

These are used to open/close sockets, to establish connections, and set special socket options.
socket(-Sockfd, ?ErrorCode)

A socket Sockfd in the AF_INET domain is created. (The AF_UNIX domain is not yet implemented). Sockfd is bound to a small integer, called socket descriptor or socket handle.

socket_set_option(+Sockfd,+OptionName,+Value)

Set socket option. At present, only the linger option is supported. ``Lingering'' is a situation when a socket continues to live after it was shut down by the owner. This is used in order to let the client program that uses the socket to finish reading or writing from/to the socket. Value represents the number of seconds to linger. The value -1 means do not linger at all.

socket_close(+Sockfd, ?ErrorCode)

Sockfd is closed. Sockets used in socket_connect/2 should not be closed by socket_close/1 as they will be closed when the corresponding stream is closed.

socket_bind(+Sockfd,+Port, ?ErrorCode)

The socket Sockfd is bound to the specified local port number.

socket_connect(+Sockfd,+Port,+Hostname,?ErrorCode)

The socket Sockfd is connected to the address (Hostname and Port). If socket_connect/4 terminates abnormally for any reason (connection refused, timeout, etc.), then XSb closes the socket Sockfd automatically, because such a socket cannot be used according to the BSD semantics. Therefore, it is always a good idea to check to the return code and reopen the socket, if the error code is not SOCK_OK.

socket_listen(+Socket, +Length, ?ErrorCode)

The socket Sockfd is defined to have a maximum backlog queue of Length pending connections.

socket_accept(+Sockfd,-SockOut, ?ErrorCode)

Block the caller until a connection attempt arrives. If the incoming queue is not empty, the first connection request is accepted, the call succeeds and returns a new socket, SockOut, which can be used for this new connection.


next up previous contents index
Next: Buffered, message-based communication. Up: Socket I/O Previous: Socket I/O   Contents   Index
Luis Fernando P. de Castro 2003-06-27