tcp_connected(?Socket)

This predicate succeeds if the Socket argument is the socket identifier of an active connection, or backtracks returning all currently active connections if Socket is unbound.

For example, this predicate can be used to shutdown all connections:

     close_all_connections :-
             tcp_connected(X),
             tcp_shutdown(X),
             fail
         ;   true.