Open - Maple Help

Sockets

 Open
 initiate a client TCP/IP connection

 Calling Sequence Open(host, port)

Parameters

 host - string; internet hostname or IP address port - string or positive integer; service name or port number, respectively

Description

 • 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 "192.139.233.24" 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].

Examples

 > $\mathrm{with}\left(\mathrm{Sockets}\right):$
 > $\mathrm{sid}≔\mathrm{Open}\left("localhost","echo"\right)$
 ${0}$ (1)
 > $\mathrm{type}\left(\mathrm{sid},\mathrm{Sockets}:-\mathrm{socketID}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{Close}\left(\mathrm{sid}\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{sid}≔\mathrm{Open}\left("no such host",1024\right)$