Socket object, used for clients and servers for TCP communications and IPC (inter-process communications) over Windows named pipes and Unix local domain sockets.

An IPC pipe is a communication channel between two processes. It may be uni-directional or bi-directional, depending on how it is created. Pipes can be automatically created for spawned subprocesses with Process.spawn.

Variables

@:value(new ArraySignal())closeSignal:Signal<NoData> = new ArraySignal()

Available on eval

connectSignal:Signal<NoData>

Emitted when the socket connects to a remote endpoint.

read onlyconnected:Bool

true when this socket is connected to a remote host or an IPC pipe.

read onlyhandlesPending:Int

(IPC only.) Number of pending sockets or pipes. Accessible using readHandle.

read onlylocalAddress:Null<SocketAddress>

The address of the local side of the socket connection, or null if not connected.

lookupSignal:Signal<Address>

Available on cross

(TCP only.) Emitted after the IP address of the hostname given in connectTcp is resolved, but before the socket connects.

@:value(new ArraySignal())lookupSignal:Signal<Address> = new ArraySignal()

Available on eval

(TCP only.) Emitted after the IP address of the hostname given in connectTcp is resolved, but before the socket connects.

read onlyremoteAddress:Null<SocketAddress>

The address of the remote side of the socket connection, or null if not connected.

timeoutSignal:Signal<NoData>

Emitted when a timeout occurs. See setTimeout.

Methods

connectFd (ipc:Bool, fd:Int):Void

Connect this socket to a file descriptor. Used internally to establish IPC channels between Haxe processes.

Parameters:

ipc

Whether IPC features (sending sockets) should be enabled.

connectIpc (options:SocketConnectIpcOptions, ?cb:Callback<NoData>):Void

Connect this socket to an IPC pipe.

Parameters:

options.path

Pipe path.

connectTcp (options:SocketConnectTcpOptions, ?cb:Callback<NoData>):Void

Connect this socket via TCP to the given remote.

If neither options.host nor options.address is specified, the host localhost is resolved via DNS and used as the address. At least one of options.host or options.address must be null.

options.localAddress and options.localPort can be used to specify what address and port to use on the local machine for the outgoing connection. If null or not specified, an address and/or a port will be chosen automatically by the system when connecting. The local address and port can be obtained using the localAddress.

Parameters:

options.port

Remote port to connect to.

options.host

Hostname to connect to, will be resolved using Dns.resolve to an address. lookupSignal will be emitted with the resolved address before the connection is attempted.

options.address

IPv4 or IPv6 address to connect to.

options.localAddress

Local IPv4 or IPv6 address to connect from.

options.localPort

Local port to connect from.

options.family

Limit DNS lookup to the given family.

destroy (?cb:Callback<NoData>):Void

Closes this socket and all underlying resources.

readHandle ():Socket

(IPC only.) Receive a socket or pipe. Should only be called when handlesPending is greater than zero.

ref ():Void

@:value({ initialDelay : 0, enable : false })setKeepAlive (enable:Bool = false, initialDelay:Int = 0):Void

(TCP only.) Enable or disable TCP keep-alive.

Parameters:

initialDelay

Initial delay in seconds. Ignored if enable is false.

@:value({ noDelay : true })setNoDelay (noDelay:Bool = true):Void

(TCP only.) Enable or disable TCP no-delay. Enabling no-delay disables Nagle's algorithm.

setTimeout (timeout:Int, ?listener:Listener<NoData>):Void

Set a timeout for socket oprations. Any time activity is detected on the socket (see below), the timer is reset to timeout. When the timer runs out, timeoutSignal is emitted. Note that a timeout will not automatically do anything to the socket - it is up to the timeoutSignal handler to perform an action, e.g. ping the remote host or close the socket.

Socket activity which resets the timer:

  • A chunk of data is received.
  • An error occurs during reading.
  • A chunk of data is written to the socket.
  • Connection is established.
  • (TCP only.) DNS lookup is finished (successfully or not).

Parameters:

timeout

Timeout in seconds, or 0 to disable.

unref ():Void

writeHandle (data:Bytes, handle:Socket):Void

(IPC only.) Send a socket or pipe in along with the given data. The socket must be connected.

Static methods

staticcreate (?options:SocketOptions):Socket

Creates an unconnected socket or pipe instance.

Parameters:

options.allowHalfOpen
options.readable

Whether the socket should be readable to the current process.

options.writable

Whether the socket should be writable to the current process.

Inherited Variables

Inherited Methods

Defined by Duplex

inlinecork ():Void

end ():Void

inlinepause ():Void

inlinepipe (to:IWritable):Void

inlineresume ():Void

inlineuncork ():Void

inlinewrite (chunk:Bytes):Bool