Availability::- use_module(library(socket)).(can be autoloaded)
tcp_connect(+Socket, +Host:+Port, -Read, -Write)
Client-interface to connect a socket to a given Port on a given Host. Port is either an integer or the name of a registered service. The fragment below connects to the http://www.swi-prolog.org using the service name instead of the hardcoded number `80'.
    Adress = 'www.swi-prolog.org':http,
    tcp_socket(Socket),
    tcp_connect(Socket, Adress, Read, Write),

This predicate can be hooked by defining the multifile-predicate socket:tcp_connect_hook/4. This hook is specifically intented for proxy negotiation. The code below shows the structure of such a hook. The predicates proxy/1 and proxy_connect/3 must be provided by the user.

:- multifile socket:tcp_connect_hook/4.

socket:tcp_connect_hook(Socket, Address, Read, Write) :-
    proxy(ProxyAdress),
    tcp_connect(Socket, ProxyAdress),
    tcp_open_socket(Socket, Read, Write),
    proxy_connect(Address, Read, Write).