object
socket
Portable abstraction over TCP sockets. Provides a high-level API for client and server socket operations that works with selected backend Prolog systems.
logtalk_load(sockets(loader))static, context_switching_calls
Supported backends: ECLiPSe, GNU Prolog, SICStus Prolog, SWI-Prolog, and Trealla Prolog.
Design rationale: Some backends (notably SICStus Prolog) do not provide low-level socket creation predicates that can be separated from binding or connecting. This library therefore provides a higher-level API with
client_open/5andserver_open/3that abstracts over these differences.Stream handling: Predicates
client_open/5andserver_accept/5return separate input and output streams opened in binary mode. For backends where the same stream is used for bidirectional communication, the same stream handle is returned in both arguments. Use standard stream predicates (put_byte/2,get_byte/2,read/2,write/2, etc.) to communicate.Options: Currently options are only defined for the
server_open/3predicate. This is expected to change in future versions for the other predicates that have an options argument.
Public predicates
client_open/5
Opens a client connection to the specified host and port using the given options. Returns separate input and output streams for bidirectional communication. The streams are opened by default in binary mode.
staticclient_open(Host,Port,InputStream,OutputStream,Options)client_open(+atom,+integer,--stream,--stream,+list) - one_or_errorsocket_error(Error)
Option
type(binary): Open the streams in binary mode. This is the default.Option
type(text): Open the streams in text mode.
client_open/4
Opens a client connection to the specified host and port using default options. Returns separate input and output streams for bidirectional communication. The streams are opened in binary mode.
staticclient_open(Host,Port,InputStream,OutputStream)client_open(+atom,+integer,--stream,--stream) - one_or_errorsocket_error(Error)server_open/3
Opens a server socket bound to the specified port using the given options. If Port is a variable, binds to an available port and unifies Port with the port number. Returns a ServerSocket handle to use with server_accept/4. The default backlog (queue length) for pending connections is 5. Use the option backlog(N) to override. This option is not supported and thus ignored by the SICStus Prolog and Trealla Prolog backends.
staticserver_open(Port,ServerSocket,Options)server_open(?integer,--compound,+list) - one_or_errorsocket_error(Error)server_open/2
Opens a server socket bound to the specified port using default options. If Port is a variable, binds to an available port and unifies Port with the port number. Returns a ServerSocket handle to use with server_accept/4. The default backlog (queue length) for pending connections is 5.
staticserver_open(Port,ServerSocket)server_open(?integer,--compound) - one_or_errorsocket_error(Error)server_accept/5
Accepts an incoming connection on the server socket, blocking until a client connects, using the given options. Returns separate input and output streams for bidirectional communication and client information as client(Host, Port) or client(Address) depending on backend. The streams are opened by default in binary mode.
staticserver_accept(ServerSocket,InputStream,OutputStream,ClientInfo,Options)server_accept(+compound,--stream,--stream,--compound,+list) - one_or_errorsocket_error(Error)
Option
type(binary): Open the streams in binary mode. This is the default.Option
type(text): Open the streams in text mode.
server_accept/4
Accepts an incoming connection on the server socket, blocking until a client connects, using default options. Returns separate input and output streams for bidirectional communication and client information as client(Host, Port) or client(Address) depending on backend. The streams are opened in binary mode.
staticserver_accept(ServerSocket,InputStream,OutputStream,ClientInfo)server_accept(+compound,--stream,--stream,--compound) - one_or_errorsocket_error(Error)server_close/1
Closes a server socket.
staticserver_close(ServerSocket)server_close(+compound) - one_or_errorclose/2
Closes a client or accepted connection by closing both the input and output streams. If the same stream is used for both, it is closed only once.
staticclose(InputStream,OutputStream)close(+stream,+stream) - one_or_errorcurrent_host/1
Returns the hostname of the current machine.
staticcurrent_host(Host)current_host(-atom) - one_or_errorProtected predicates
(no local declarations; see entity ancestors if any)
Private predicates
(no local declarations; see entity ancestors if any)
Operators
(none)