Module

Node.Net.Socket

Package
purescript-node-net
Repository
purescript-node/purescript-node-net

#ConnectOptions Source

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 Source

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

#Socket Source

data Socket

An ICP endpoint or TCP socket.

#SocketOptions Source

data SocketOptions

Options to configure the basics of a Socket.

#bufferSize Source

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 Source

bytesRead :: Socket -> Effect Int

The number of bytes recieved on the Socket.

#bytesWritten Source

bytesWritten :: Socket -> Effect Int

The number of bytes sent on the Socket.

#connect Source

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 Source

connectFamily :: Option ConnectOptions Int

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

#connectHints Source

connectHints :: Option ConnectOptions Int

DNS lookup hints.

#connectHost Source

connectHost :: Option ConnectOptions String

The host to configure TCP Sockets.

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

#connectICP Source

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 Source

connectLocalAddress :: Option ConnectOptions String

Address the Socket should connect from.

#connectLocalPort Source

connectLocalPort :: Option ConnectOptions Int

Port the Socket should connect from.

#connectPath Source

connectPath :: Option ConnectOptions String

The path to configure ICP Sockets.

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

#connectPort Source

connectPort :: Option ConnectOptions Int

The port to configure TCP Servers.

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

#connectTCP Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

destroyed :: Socket -> Effect Boolean

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

#end Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

pause :: Socket -> Effect Unit

Pauses 'data' events from being emitted.

#pending Source

pending :: Socket -> Effect Boolean

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

#remoteAddress Source

remoteAddress :: Socket -> Effect (Maybe String)

Attempts to return the address a Socket is connected to.

#remoteFamily Source

remoteFamily :: Socket -> Effect (Maybe String)

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

#remotePort Source

remotePort :: Socket -> Effect (Maybe Int)

Attempts to return the port a Socket is connected to.

#resume Source

resume :: Socket -> Effect Unit

Resumes emitting 'data' events.

#setEncoding Source

setEncoding :: Socket -> Encoding -> Effect Unit

Sets the Encoding for the data read on the Socket.

#setKeepAlive Source

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 Source

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 Source

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 Source

socketAllowHalfOpen :: Option SocketOptions Boolean

Allows half open TCP connections. Defaults to false.

#socketFd Source

socketFd :: Option SocketOptions FileDescriptor

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

#socketHost Source

socketHost :: Option SocketOptions String

The host to configure TCP Sockets.

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

#socketPath Source

socketPath :: Option SocketOptions String

The path to configure ICP Sockets.

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

#socketPort Source

socketPort :: Option SocketOptions Int

The port to configure TCP Sockets.

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

#socketReadable Source

socketReadable :: Option SocketOptions Boolean

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

#socketTimeout Source

socketTimeout :: Option SocketOptions Int

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

#socketWritable Source

socketWritable :: Option SocketOptions Boolean

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

#write Source

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 Source

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.