initiate a client TCP/IP connection
string; internet hostname or IP address
string or positive integer; service name or port number, respectively
The procedure Open is used to initiate a client TCP/IP connection to a given internet address or hostname host at a given port or service name port. If the connection is established successfully, then a valid socket ID is returned. This socket ID is used as an argument to most procedures that operate on the connection.
The argument host must be of type string. It specifies the name of the host to connect to, and can be given in the form of a symbolic hostname (such as "www.maplesoft.com" or "localhost") or in the form of a numeric IP address (such as "220.127.116.11" or "127.0.0.1").
The argument port specifies the port number to connect to at the remote host. It can be specified either as a numeric port number (which must be a small (16-bit) positive integer) or as the name of a known internet service (such as "echo", "ftp", or "smtp"), in the form of a Maple string. If a service name is used, but the service is not recognized, then an exception is raised.
An attempt is made to contact the service at the given host and port. If this connection succeeds, then a valid socket ID is returned. In case the connection fails, an exception is raised.
Common reasons why a connection may fail are that the hostname cannot be resolved to an internet address, the host may not be reachable, or the host may be refusing to accept connections on the specified port (or service).
Once you have obtained a valid socket ID, you can communicate with the service at the remote side of the connection (the ``peer'') by using the I/O routines in the Sockets package. For example, see Sockets[Read] and Sockets[Write]. When you have finished using a socket connection, you should close it by using the procedure Sockets[Close].
sid ≔ Open⁡localhost,echo
sid ≔ Open⁡no such host,1024
Error, (in Sockets:-Open) cannot establish TCP connection to `no such host' at port 1024
Download Help Document