• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

6.5 Socket predicate reference
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog C-library
        • library(socket): Network socket (TCP and UDP) library
          • Socket predicate reference
            • socket_create/2
            • tcp_socket/1
            • unix_domain_socket/1
            • tcp_close_socket/1
            • tcp_open_socket/2
            • tcp_open_socket/3
            • tcp_bind/2
            • tcp_listen/2
            • tcp_accept/3
            • tcp_connect/2
            • rewrite_host/3
            • tcp_connect/4
            • tcp_connect/3
            • tcp_select/3
            • try_proxy/4
            • proxy_for_url/3
            • udp_socket/1
            • udp_receive/4
            • udp_send/4
            • tcp_setopt/2
            • tcp_fcntl/3
            • tcp_getopt/2
            • host_address/3
            • tcp_host_to_address/2
            • gethostname/1
            • ip_name/2
            • negotiate_socks_connection/2
Availability::- use_module(library(socket)).(can be autoloaded)
Source[det]tcp_connect(+SocketId, +Address)
Connect SocketId. After successful completion, tcp_open_socket/3 can be used to create I/O-Streams to the remote socket. This predicate is part of the low level client API. A connection to a particular host and port is realised using these steps:
    tcp_socket(Socket),
    tcp_connect(Socket, Host:Port),
    tcp_open_socket(Socket, StreamPair)

Typical client applications should use the high level interface provided by tcp_connect/3 which avoids resource leaking if a step in the process fails, and can be hooked to support proxies. For example:

    setup_call_cleanup(
        tcp_connect(Host:Port, StreamPair, []),
        talk(StreamPair),
        close(StreamPair))

If SocketId is an AF_UNIX socket (see unix_domain_socket/1), Address is an atom or string denoting a file name.

ClioPatria (version V3.1.1-51-ga0b30a5)