Attempts to connect to a socket on a server.
comm
connect-to-tcp-server hostspec service &key errorp timeout local-address local-port keepalive nodelay ipv6 => socket-handle
hostspec⇩ |
An integer or a string or an ipv6-address object. |
service⇩ |
A string or a fixnum. |
errorp⇩ |
A boolean. |
timeout⇩ |
A positive number, or nil . |
local-address⇩ | nil , an integer, a string or an ipv6-address object. |
local-port⇩ | nil , a string or a fixnum. |
keepalive⇩ |
A generalized boolean. |
nodelay⇩ |
A generalized boolean. |
ipv6⇩ | nil , t or :any . |
socket-handle⇩ |
A socket handle suitable for a socket-stream or a subclass, or nil . |
The function connect-to-tcp-server
attempts to connect to a socket on a server and returns a socket handle for the connection if successful. This socket handle can then be used as the socket in a socket-stream or the object in async-io-state, or in FLI functions using the native TCP socket interface.
The IP address to connect to is specified by hostspec, and the service to provide is specified by service. These two arguments are interpreted as described in 25.3 Specifying the target for connecting and binding a socket.
If errorp is nil
, failure to connect (possibly after timeout seconds) returns nil
, otherwise an error is signaled.
timeout specifies a connection timeout. connect-to-tcp-server
waits for at most timeout seconds for the TCP connection to be made. If timeout is nil
it waits until the connection attempt succeeds or fails. On failure, connect-to-tcp-server
signals an error or returns nil
according to the value of errorp. To provide a timeout for reads after the connection is made, see read-timeout in socket-stream. The default value of timeout is nil
.
If local-address is nil
then the operating system chooses the local address of the socket. Otherwise the value is interpreted as for hostspec and specifies the local address of the socket. The default value of local-address is nil
.
If local-port is nil
then the operating system chooses the local port of the socket. Otherwise the string or fixnum value is interpreted as for service and specifies the local port of the socket. The default value of local-port is nil
.
If keepalive is true, SO_KEEPALIVE
is set on the socket. The default value of keepalive is nil
.
If nodelay is true, TCP_NODELAY
is set on the socket. The default value of nodelay is t
.
ipv6 specifies the address family to use when hostspec is a string. When ipv6 is :any
, connect-to-tcp-server
uses either of IPv4 or IPv6. When ipv6 is t
, it uses only IPv6 addresses, and when ipv6 is nil
it tries only IPv4. The default value of ipv6 is :any
.
/etc/services
. If it is not there, the manual entry for services can be used to find it.connect-to-tcp-server
is useful when want to associate further information with the stream. You can define a subclass of socket-stream, connect using connect-to-tcp-server
, and call make-instance with your subclass, passing socket-handle as the socket.
socket-stream
open-tcp-stream
close-socket-handle
create-async-io-state
25 TCP and UDP socket communication and SSL
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:26