new NetSocket()
Represents a socket-like interface to a TCP connection on either the
client or the server side.
- Source:
Methods
close(handler)
Close the NetSocket and notify the
handler when the operation completes.
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function |
- Source:
closeHandler(handler) → {NetSocket}
Set a handler that will be called when the NetSocket is closed
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function | the handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- NetSocket
drainHandler(handler) → {NetSocket}
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function |
- Source:
Returns:
- Type
- NetSocket
end(handler)
Calls NetSocket#end.
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function |
- Source:
endHandler(endHandler) → {NetSocket}
This handler might be called after the close handler when the socket is paused and there are still buffers to deliver.
Parameters:
| Name | Type | Description |
|---|---|---|
endHandler |
function |
- Source:
Returns:
- Type
- NetSocket
exceptionHandler(handler) → {NetSocket}
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function |
- Source:
Returns:
- Type
- NetSocket
fetch(amount) → {NetSocket}
Parameters:
| Name | Type | Description |
|---|---|---|
amount |
number |
- Source:
Returns:
- Type
- NetSocket
handler(handler) → {NetSocket}
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function |
- Source:
Returns:
- Type
- NetSocket
indicatedServerName() → {string}
Returns the SNI server name presented during the SSL handshake by the client.
- Source:
Returns:
the indicated server name
- Type
- string
isSsl() → {boolean}
- Source:
Returns:
true if this NetSocket is encrypted via SSL/TLS.
- Type
- boolean
localAddress() → {SocketAddress}
- Source:
Returns:
the local address for this socket
- Type
- SocketAddress
pause() → {NetSocket}
- Source:
Returns:
- Type
- NetSocket
pipe() → {Pipe}
Pause this stream and return a to transfer the elements of this stream to a destination .
The stream will be resumed when the pipe will be wired to a
WriteStream.
- Source:
Returns:
a pipe
- Type
- Pipe
pipeTo(dst, handler)
Pipe this
ReadStream to the WriteStream.
Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the handler will be
called with the result.
Parameters:
| Name | Type | Description |
|---|---|---|
dst |
WriteStream | the destination write stream |
handler |
function |
- Source:
remoteAddress() → {SocketAddress}
- Source:
Returns:
the remote address for this socket
- Type
- SocketAddress
resume() → {NetSocket}
- Source:
Returns:
- Type
- NetSocket
sendFile(filename, offset, length, resultHandler) → {NetSocket}
Same as NetSocket#sendFile but also takes a handler that will be called when the send has completed or
a failure has occurred
Parameters:
| Name | Type | Description |
|---|---|---|
filename |
string | file name of the file to send |
offset |
number | offset |
length |
number | length |
resultHandler |
function | handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- NetSocket
setWriteQueueMaxSize(maxSize) → {NetSocket}
Parameters:
| Name | Type | Description |
|---|---|---|
maxSize |
number |
- Source:
Returns:
- Type
- NetSocket
upgradeToSsl(serverName, handler) → {NetSocket}
Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.
Parameters:
| Name | Type | Description |
|---|---|---|
serverName |
string | the server name |
handler |
function | the handler will be notified when it's upgraded |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- NetSocket
write(message, handler)
Like WriteStream#write but with an
handler called when the message has been written
or failed to be written.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
Buffer | |
handler |
function |
- Source:
writeHandlerID() → {string}
When a
NetSocket is created it automatically registers an event handler with the event bus, the ID of that
handler is given by writeHandlerID.
Given this ID, a different event loop can send a buffer to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other connections which are owned by different event loops.
- Source:
Returns:
the write handler ID
- Type
- string
writeQueueFull() → {boolean}
This will return
true if there are more bytes in the write queue than the value set using NetSocket#setWriteQueueMaxSize
- Source:
Returns:
true if write queue is full
- Type
- boolean