net~ NetConn

NetConn is a connection to a remote host.

Constructor

new NetConn()

Methods

Close()

Close closes the connection.
Throws:
- The error encountered during connection closing.
Type
error
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.Close();

Recv(N) → {Uint8Array}

Recv receives data from the connection with a timeout. If N is 0, it will read up to 4096 bytes.
Parameters:
NameTypeDescription
NnumberThe number of bytes to receive.
Throws:
- The error encountered during data receiving.
Type
error
Returns:
- The received data in an array.
Type: 
Uint8Array
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
let data = c.Recv(1024);

RecvHex(N) → {string}

RecvHex receives data from the connection with a timeout in hex format. If N is 0, it will read up to 4096 bytes.
Parameters:
NameTypeDescription
NnumberThe number of bytes to receive.
Throws:
- The error encountered during data receiving.
Type
error
Returns:
- The received data in hex format.
Type: 
string
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
let data = c.RecvHex(1024);

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 up to 4096 bytes.
Parameters:
NameTypeDescription
NnumberThe number of bytes to receive.
Throws:
- The error encountered during data receiving.
Type
error
Returns:
- The received data as a string.
Type: 
string
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
let data = c.RecvString(1024);

Send(data)

Send sends data to the connection with a timeout.
Parameters:
NameTypeDescription
dataUint8ArrayThe data to send.
Throws:
- The error encountered during data sending.
Type
error
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.Send(new Uint8Array([1, 2, 3]));

SendArray(data)

SendArray sends array data to connection.
Parameters:
NameTypeDescription
dataUint8ArrayThe array data to send.
Throws:
- The error encountered during data sending.
Type
error
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.SendArray(new Uint8Array([1, 2, 3]));

SendHex(data)

SendHex sends hex data to connection.
Parameters:
NameTypeDescription
datastringThe hex data to send.
Throws:
- The error encountered during data sending.
Type
error
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.SendHex('0x123');

SetTimeout(value)

SetTimeout sets read/write timeout for the connection (in seconds).
Parameters:
NameTypeDescription
valuenumberThe timeout value in seconds.
Example
let m = require('nuclei/net');
let c = m.Open('tcp', 'localhost:8080');
c.SetTimeout(5);