Module sockets
:- use_module(library(sockets)).
Predicates for handling network sockets, both as a server and as a client. As a server, you should open a socket an call socket_server_accept/4
to get a stream for each connection. As a client, you should just open a socket and you will receive a stream. In both cases, with a stream, you can use the usual predicates to read and write to the stream.
socket_client_open(+Addr, -Stream, +Options).
Open a socket to a server, returning a stream. Addr must satisfy Addr = Address:Port
.
The following options are available:
alias(+Alias)
: Set an alias to the streameof_action(+Action)
: Defined what happens if the end of the stream is reached. Values:error
,eof_code
andreset
.reposition(+Boolean)
: Specifies whether repositioning is required for the stream.false
is the default.type(+Type)
: Type can betext
orbinary
. Defines the type of the stream, if it's optimized for plain text or just binary
socket_server_open(+Addr, -ServerSocket).
Open a server socket, returning a ServerSocket. Use that ServerSocket to accept incoming connections in socket_server_accept/4
. Addr must satisfy Addr = Address:Port
. Depending on the operating system configuration, some ports might be reserved for superusers.
socket_server_accept(+ServerSocket, -Client, -Stream, +Options).
Given a ServerSocket and a list of Options, accepts a incoming connection, returning data from the Client and a Stream to read or write data.
The following options are available:
alias(+Alias)
: Set an alias to the streameof_action(+Action)
: Defined what happens if the end of the stream is reached. Values:error
,eof_code
andreset
.reposition(+Boolean)
: Specifies whether repositioning is required for the stream.false
is the default.type(+Type)
: Type can betext
orbinary
. Defines the type of the stream, if it's optimized for plain text or just binary
socket_server_close(+ServerSocket).
Stops listening on that ServerSocket. It's recommended to always close a ServerSocket once it's no longer needed
current_hostname(-HostName).
Returns the current hostname of the computer in which Scryer Prolog is executing right now