class Socket
package js.node.net
extends Duplex › Readable › Stream › EventEmitter
extended by TLSSocket, ReadStream, WriteStream
Constructor
Variables
bufferSize:Int
Socket
has the property that socket.write
always works. This is to help users get up and running quickly.
The computer cannot always keep up with the amount of data that is written to a socket - the network connection
simply might be too slow. Node will internally queue up the data written to a socket and send it out over the
wire when it is possible. (Internally it is polling on the socket's file descriptor for being writable).
The consequence of this internal buffering is that memory may grow. This property shows the number of characters currently buffered to be written. (Number of characters is approximately equal to the number of bytes to be written, but the buffer may contain strings, and the strings are lazily encoded, so the exact number of bytes is not known.)
Users who experience large or growing bufferSize
should attempt to "throttle" the data flows
in their program with pause
and resume
.
read onlyencrypted:Bool
Always true for TLSSocket instances.
May be used to distinguish TLS sockets from regular ones.
read onlylocalAddress:String
The string representation of the local IP address the remote client is connecting on. For example, if you are listening on '0.0.0.0' and the client connects on '192.168.1.1', the value would be '192.168.1.1'.
read onlyremoteAddress:String
The string representation of the remote IP address. For example, '74.125.127.100' or '2001:4860:a005::68'.
read onlyremoteFamily:SocketAdressFamily
The string representation of the remote IP family. 'IPv4' or 'IPv6'.
Methods
address():SocketAdress
Returns the bound address, the address family name and port of the socket as reported by the operating system.
connect(options:EitherType<SocketConnectOptionsTcp, SocketConnectOptionsUnix>, ?connectListener:() ‑> Void):Socket
connect(path:String, ?connectListener:() ‑> Void):Socket
connect(port:Int, ?connectListener:() ‑> Void):Socket
connect(port:Int, host:String, ?connectListener:() ‑> Void):Socket
Opens the connection for a given socket.
If port
and host
are given, then the socket will be opened as a TCP socket,
if host
is omitted, localhost will be assumed.
If a path
is given, the socket will be opened as a unix socket to that path.
Normally this method is not needed, as Net.createConnection
opens the socket.
Use this only if you are implementing a custom Socket
.
This function is asynchronous. When the 'connect' event is emitted the socket is established. If there is a problem connecting, the 'connect' event will not be emitted, the 'error' event will be emitted with the exception
The connectListener
parameter will be added as an listener for the 'connect' event.
destroy(?exception:Error):Void
A boolean value that indicates if the connection is destroyed or not. Once a connection is destroyed no further data can be transferred using it.
define in Stream/Readable.hx
ref():Socket
Opposite of unref
, calling ref
on a previously unref
d socket will not let the program exit
if it's the only socket left (the default behavior).
If the socket is ref
d calling ref
again will have no effect.
setKeepAlive(enable:Bool, ?initialDelay:Int):Void
setKeepAlive(?initialDelay:Int):Void
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
enable
defaults to false.
Set initialDelay
(in milliseconds) to set the delay between the last data packet received and
the first keepalive probe.
Setting 0 for initialDelay
will leave the value unchanged from the default (or previous) setting.
Defaults to 0.
setNoDelay(?noDelay:Bool):Void
Disables the Nagle algorithm.
By default TCP connections use the Nagle algorithm, they buffer data before sending it off.
Setting true for noDelay
will immediately fire off data each time write
is called.
noDelay
defaults to true.
setTimeout(timeout:Int, ?callback:() ‑> Void):Void
Sets the socket to timeout after timeout
milliseconds of inactivity on the socket.
By default Socket
do not have a timeout.
When an idle timeout is triggered the socket will receive a 'timeout' event but the connection will not be severed.
The user must manually end
or destroy
the socket.
If timeout
is 0, then the existing idle timeout is disabled.
The optional callback
parameter will be added as a one time listener for the 'timeout' event.