sitelogo
server_start/4

Starts a server listening for socket connections

server_start(+Port, +Backlog, +Callback, -Server)

server_start/4 opens a server socket listening on port Port for incoming connection requests. Backlog sets the maximum queue length for incoming connection requests. If a connection request arrives when the queue is full, the connection is refused.
When a connection request arrives, the server will call the user defined callback predicate Callback, which has to handle the new connection. If the first argument of the the callback predicate is a variable, then this argument will be replaced by the socket argument, that has been created for the new connection.

Arguments

Port               integer
Backlog            integer
Callback           compound or atom
Server             object

Examples

main(_) :-
    server_start(1352, 3, accept_connection(_), _).

accept_connection(Socket) :- open(Socket, read, Input, [socket,buffered,binary]), open(Socket, write, Output, [socket,buffered,binary]), receive(Input, Request), handle_request(Request, Anwer), send(Output, Answer), close(Input), close(Output), close(Socket).

handle_request(Request, Answer) :- ...

See also

server_start/4, server_stop/1, client_start/3, client_stop/1, listener_start/3, listener_stop/1, send/2, receive/2.


Up read on...
scroll to top managed with ubiCMS