connect

Synopsis

$ connect("host", port, [timeout], [&closure], [option => value, ...])

connects to the specified host:port and returns a $handle. Check for issues connecting to a host with checkError(). If &closure is specified, this call will not block. &closure will be called when a connection is established.

Parameters

"host" - the hostname or IP address to connect to

port - the port number to connect to

timeout - the desired timeout (in milliseconds), 0 specifies an indefinite timeout, default is 60 seconds

&closure - if a closure is specified, this function will not block, instead when the connection is established, &closure will be called. When called, the closure receives the following arguments:
ArgumentDescription
$1a $handle for the connected socket

option => value - various socket options.

Returns

A $handle to a socket. This handle can be read from and written to using Sleep's IO functions.

Errors

Examples

$handle = connect(@ARGV[0], 31337); println($handle, "hello echo server"); $text = readln($handle); println("Read: $text"); closef($handle);

$ java -jar sleep.jar echocl.sl 127.0.0.1 Read: PONG! hello echo server

See Also