Class: SyncSocket

SyncSocket

This is intended to be a net.Socket "like" class, with the important distinction of all methods being synchronous instead of asynchronous.

new SyncSocket(options)

Creates a SyncSocket
Name Type Description
options Object optional key/value pairs of options, all optional
Name Type Description
workerPort number optional the port to use for the request TCP server used to communicate the TCP client data, must be free to work
timeout number optional the amount of time in ms to test to make sure the helper thread is responding to requests before throwing an Error

Methods

Object address()

Returns the bound address, the address family name and port of the socket as reported by the operating system. Returns an object with three properties, e.g. `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
Returns: Object
the remote `family`, `address`, and `port` in an object

SyncSocket connect(options, host)

A synchronous version of net.Socket.connect(options). Note: it does not accept a connectListener as part of the argument
Name Type Description
options Object | number options to use to create the connection. Accepts all the options net.Socket.connect does (as it's just sent to that function). Alternatively can the just the number `port` to connect to.
host string optional the host to connect to, if options was used as `port`.
Returns: SyncSocket
itself

disconnect()

Disconnects/Destroys the connection and its workers

string read(buffer, blocking)

Reads a socket for data. Basically a replacement for on('data');
Name Type Default Description
buffer number 16384 optional how many bytes to read from the buffer
blocking boolean false optional True if you want to block the read until data is available, false/undefined otherwise (normal behavior)
Returns: string
string read from the socket, or undefined if no data to read

write(data, encoding)

Writes data to the socket
Name Type Description
data string data to write to the socket
encoding string optional encoding of the data being written, defaults to 'utf-8'