Module

Node.Net.Socket

#ConnectOptions

data ConnectOptions

Options to configure the connecting side of a Socket. These options decide whether the Socket is ICP or TCP.

One of path or port must be set. Setting path will make the Socket ICP. Setting port will make the Socket TCP.

#Lookup

type Lookup = { address :: String, family :: Maybe Int, host :: String }

#Socket

data Socket :: Type

An ICP endpoint or TCP socket.

#SocketOptions

data SocketOptions

Options to configure the basics of a Socket.

#bufferSize

bufferSize :: Socket -> Effect (Maybe Int)

The number of characters buffered to be written on a Socket.

N.B. The number of characters is not equal to the number of bytes.

#bytesRead

bytesRead :: Socket -> Effect Int

The number of bytes recieved on the Socket.

#bytesWritten

bytesWritten :: Socket -> Effect Int

The number of bytes sent on the Socket.

#connect

connect :: Socket -> Options ConnectOptions -> Effect Unit -> Effect Unit

Creates a custom ICP or TCP connection on the Socket. Normally, createConnection should be used to create the socket.

#connectFamily

connectFamily :: Option ConnectOptions Int

Version of IP stack, either 4 or 6. Defaults to 4.

#connectHints

connectHints :: Option ConnectOptions Int

DNS lookup hints.

#connectHost

connectHost :: Option ConnectOptions String

The host to configure TCP Sockets.

Determines the host the Socket will attempt to connect to. Defaults to localhost.

#connectICP

connectICP :: Socket -> String -> Effect Unit -> Effect Unit

Creates a custom ICP connection on the Socket. Normally, createConnectionICP should be used to create the socket.

#connectLocalAddress

connectLocalAddress :: Option ConnectOptions String

Address the Socket should connect from.

#connectLocalPort

connectLocalPort :: Option ConnectOptions Int

Port the Socket should connect from.

#connectPath

connectPath :: Option ConnectOptions String

The path to configure ICP Sockets.

Determines the ICP endpoint the Socket will attempt to connect to.

#connectPort

connectPort :: Option ConnectOptions Int

The port to configure TCP Servers.

Determines the TCP endpoint the Server will attempt to listen on.

#connectTCP

connectTCP :: Socket -> Int -> String -> Effect Unit -> Effect Unit

Creates a custom TCP connection on the Socket. Normally, createConnectionTCP should be used to create the socket.

#connecting

connecting :: Socket -> Effect Boolean

Returns true if connect was called, but the 'connect' event hasn't been emitted yet. Returns false any other time.

#createConnection

createConnection :: Options SocketOptions -> Effect Unit -> Effect Socket

Creates an ICP or TCP Socket, initiates a connection, returns the Socket, adds the callback as a one-time listener for the 'connect' event, and emits the 'connect' event.

#createConnectionICP

createConnectionICP :: String -> Effect Unit -> Effect Socket

Creates an ICP Socket, initiates a connection, returns the Socket, adds the callback as a one-time listener for the 'connect' event, and emits the 'connect' event.

#createConnectionTCP

createConnectionTCP :: Int -> String -> Effect Unit -> Effect Socket

Creates a TCP Socket, initiates a connection, returns the Socket, adds the callback as a one-time listener for the 'connect' event, and emits the 'connect' event.

#destroy

destroy :: Socket -> Maybe Error -> Effect Unit

Ensure no more I/O activity happens on the socket.

If an Error is provided, an 'error' event is emitted.

#destroyed

destroyed :: Socket -> Effect Boolean

Returns true if the connection is destroyed and can no longer transfer data.

#end

end :: Socket -> Buffer -> Effect Unit -> Effect Unit

Send a FIN packet to half-close the Socket. The server might still send more data. Invokes the callback after the Socket is finished.

#endString

endString :: Socket -> String -> Encoding -> Effect Unit -> Effect Unit

Send a FIN packet to half-close the Socket. The server might still send more data. Invokes the callback after the Socket is finished.

#localAddress

localAddress :: Socket -> Effect (Maybe String)

Attempts to return the address a client is connecting on. E.g. if a client connects from 192.168.1.1, the result would be Just "192.168.1.1".

#localPort

localPort :: Socket -> Effect (Maybe Int)

Attempts to return the port a client is connecting on. E.g. if a client connects from 80, the result would be Just 80.

#onClose

onClose :: Socket -> (Boolean -> Effect Unit) -> Effect Unit

Attaches the callback as a listener to the 'close' event. The Boolean represents whether an error happened during transmission.

'close' is emitted when an close occurs.

#onConnect

onConnect :: Socket -> Effect Unit -> Effect Unit

Attaches the callback as a listener to the 'connect' event.

'connect' is emitted when a new connection is successfully establed.

#onData

onData :: Socket -> (Either Buffer String -> Effect Unit) -> Effect Unit

Attaches the callback as a listener to the 'data' event.

'data' is emitted when a data is recieved. Data will be lost if there is no listener when 'data' is emitted.

#onDrain

onDrain :: Socket -> Effect Unit -> Effect Unit

Attaches the callback as a listener to the 'drain' event.

'drain' is emitted when the write buffer is empty.

#onEnd

onEnd :: Socket -> Effect Unit -> Effect Unit

Attaches the callback as a listener to the 'end' event.

'end' is emitted when the other end of the Socket sends a FIN packet.

#onError

onError :: Socket -> (Error -> Effect Unit) -> Effect Unit

Attaches the callback as a listener to the 'error' event.

'error' is emitted when an error occurs. 'close' is emitted directly after this event.

#onLookup

onLookup :: Socket -> (Either Error Lookup -> Effect Unit) -> Effect Unit

Attaches the callback as a listener to the 'lookup' event.

'lookup' is emitted after resolving the hostname but before connecting.

#onReady

onReady :: Socket -> Effect Unit -> Effect Unit

Attaches the callback as a listener to the 'ready' event.

'ready' is emitted when the Socket is ready to be used.

#onTimeout

onTimeout :: Socket -> Effect Unit -> Effect Unit

Attaches the callback as a listener to the 'timeout' event.

'timeout' is emitted if the Socket times out from inactivity. The Socket is still open and should be manually closed.

#pause

pause :: Socket -> Effect Unit

Pauses 'data' events from being emitted.

#pending

pending :: Socket -> Effect Boolean

Returns true if the Socket is not connected yet. Returns false otherwise.

#remoteAddress

remoteAddress :: Socket -> Effect (Maybe String)

Attempts to return the address a Socket is connected to.

#remoteFamily

remoteFamily :: Socket -> Effect (Maybe String)

Attempts to return the IP family a Socket is connected to, either "IPv4" or "IPv6".

#remotePort

remotePort :: Socket -> Effect (Maybe Int)

Attempts to return the port a Socket is connected to.

#resume

resume :: Socket -> Effect Unit

Resumes emitting 'data' events.

#setEncoding

setEncoding :: Socket -> Encoding -> Effect Unit

Sets the Encoding for the data read on the Socket.

#setKeepAlive

setKeepAlive :: Socket -> Boolean -> Int -> Effect Unit

Sets keep-alive behavior. When true, it enables the behavior. When false, it disables the behavior. The Int is the initial delay in milliseconds before the first probe is sent to an idle Socket.

#setNoDelay

setNoDelay :: Socket -> Boolean -> Effect Unit

When true, disables the Nagle algorithm and sends data immedately. When false, enables the Nagle algorithm and buffers data before sending.

#setTimeout

setTimeout :: Socket -> Int -> Effect Unit -> Effect Unit

When 0, disables the existing timeout. Otherwise, sets the Socket to timeout after the given milliseconds. Adds the callback as a listener for the 'timeout' event.

#socketAllowHalfOpen

socketAllowHalfOpen :: Option SocketOptions Boolean

Allows half open TCP connections. Defaults to false.

#socketFd

socketFd :: Option SocketOptions FileDescriptor

Creates a Socket around the given FileDescriptor. If not specified, creates a new Socket.

#socketHost

socketHost :: Option SocketOptions String

The host to configure TCP Sockets.

Determines the host the Socket will attempt to connect to. Defaults to localhost.

#socketPath

socketPath :: Option SocketOptions String

The path to configure ICP Sockets.

Determines the ICP endpoint the Socket will attempt to connect to.

#socketPort

socketPort :: Option SocketOptions Int

The port to configure TCP Sockets.

Determines the TCP endpoint the Socket will attempt to connect to.

#socketReadable

socketReadable :: Option SocketOptions Boolean

Allows reads if a FileDescriptor is also set. Defaults to false.

#socketTimeout

socketTimeout :: Option SocketOptions Int

Passed to setTimeout when the Socket is created but before it starts the connection.

#socketWritable

socketWritable :: Option SocketOptions Boolean

Allows writes if a FileDescriptor is also set. Defaults to false.

#write

write :: Socket -> Buffer -> Effect Unit -> Effect Boolean

Sends data on the Socket and invokes the callback after the data is finally written. Returns true if the data was flushed successfully. Returns false if the data was queued. Emits a 'drain' event after the buffer is free.

#writeString

writeString :: Socket -> String -> Encoding -> Effect Unit -> Effect Boolean

Sends data on the Socket and invokes the callback after the data is finally written. Returns true if the data was flushed successfully. Returns false if the data was queued. Emits a 'drain' event after the buffer is free.

Modules