tcp_accept(+PassiveSocket, -Socket)

tcp_accept/2 is used to accept a connection request on PassiveSocket and binding a Prolog stream to it. The input and output streams created by calling this predicate can be obtained by using the Socket output argument when calling tcp_input_stream/2 and tcp_output_stream/2, respectively.

To arrange for a server to make a callback whenever there is a connection request:

         ...
         tcp_create_listener(Port, Host, Passive),
         tcp_create_input_callback(Passive, accept(Passive)),
         ...
     
     accept(Passive) :-
         tcp_accept(Passive, Socket),
         ...
     

Probably you will want to make the newly created socket a callback as well, so then the clause for accept/1 in the preceding example would be:

     accept(Passive) :-
         tcp_accept(Passive, Socket),
         tcp_create_input_callback(Socket, input_on(Socket)).
     

Where input_on/1 is as defined in the example for tcp_create_input_callback/2.