net

(net).NetConn

NetConn is a connection to a remote host.

Kind: inner class of net

netConn.Close()

Close closes the connection.

Kind: instance method of NetConn
Throws:

  • error - The error encountered during connection closing.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.Close();

netConn.Recv([N]) ⇒ Uint8Array

Recv receives data from the connection with a timeout. If N is 0, it will read all available data.

Kind: instance method of NetConn
Returns: Uint8Array - - The received data in an array.
Throws:

  • error - The error encountered during data receiving.
ParamTypeDefaultDescription
[N]number0The number of bytes to receive.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
let data = c.Recv(1024);

netConn.RecvHex([N]) ⇒ string

RecvHex receives data from the connection with a timeout in hex format. If N is 0, it will read all available data.

Kind: instance method of NetConn
Returns: string - - The received data in hex format.
Throws:

  • error - The error encountered during data receiving.
ParamTypeDefaultDescription
[N]number0The number of bytes to receive.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
let data = c.RecvHex(1024);

netConn.RecvString([N]) ⇒ string

RecvString receives data from the connection with a timeout. Output is returned as a string. If N is 0, it will read all available data.

Kind: instance method of NetConn
Returns: string - - The received data as a string.
Throws:

  • error - The error encountered during data receiving.
ParamTypeDefaultDescription
[N]number0The number of bytes to receive.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
let data = c.RecvString(1024);

netConn.Send(data)

Send sends data to the connection with a timeout.

Kind: instance method of NetConn
Throws:

  • error - The error encountered during data sending.
ParamTypeDescription
dataUint8ArrayThe data to send.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.Send(new Uint8Array([1, 2, 3]));

netConn.SendArray(data)

SendArray sends array data to connection.

Kind: instance method of NetConn
Throws:

  • error - The error encountered during data sending.
ParamTypeDescription
dataUint8ArrayThe array data to send.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.SendArray(new Uint8Array([1, 2, 3]));

netConn.SendHex(data)

SendHex sends hex data to connection.

Kind: instance method of NetConn
Throws:

  • error - The error encountered during data sending.
ParamTypeDescription
datastringThe hex data to send.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.SendHex('0x123');

netConn.SetTimeout(value)

SetTimeout sets read/write timeout for the connection (in seconds).

Kind: instance method of NetConn

ParamTypeDescription
valuenumberThe timeout value in seconds.

Example

let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.SetTimeout(5);

(net).Open(protocol, address) ⇒ NetConn

Open opens a new connection to the address with a timeout. Supported protocols: tcp, udp.

Kind: inner method of net
Returns: NetConn - - The NetConn object representing the connection.
Throws:

  • error - The error encountered during connection opening.
ParamTypeDescription
protocolstringThe protocol to use.
addressstringThe address to connect to.

Example

let m = require('nuclei/net'); 
let conn = m.Open('tcp', 'localhost:8080');

(net).OpenTLS(protocol, address) ⇒ NetConn

OpenTLS opens a new connection to the address with a timeout. Supported protocols: tcp, udp.

Kind: inner method of net
Returns: NetConn - - The NetConn object representing the connection.
Throws:

  • error - The error encountered during connection opening.
ParamTypeDescription
protocolstringThe protocol to use.
addressstringThe address to connect to.

Example

let m = require('nuclei/net'); 
let conn = m.OpenTLS('tcp', 'localhost:8080');