Starts a server listening for socket connections
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.
Port integer Backlog integer Callback compound or atom Server object
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) :-
...
| scroll to top |
|