Network Sniffer - Software network packet sniffer & protocol analyzer for Windows
Docs

INetworkSession Interface

interface INetworkSession {
    // Methods
    ${connect}(hostName: string, port: number): Promise<void>;
    ${stop}(): void;
    ${send#send1}(text: string): void;
    ${send#send2}(byte: number): void;
    ${send#send3}(bytes: number [] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView): void;
    ${receive}(): Promise<Uint8Array>;
}
// This interface is not available in managed environment
// This interface is not available in native environment

INetworkSession Methods

connect

connect(hostName: string, port: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
hostName
Host name. This may be host domain name, IP address or other name that can be resolved.
port
Port number.

Starts a connect operation on a session. Returns a promise that can be awaited. A promise object is completed when the connection either succeeds or fails.

stop

stop(): void;
// This method is not available in managed environment
// This method is not available in native environment

Stop the running TCP session.

send

send(text: string): void;
// This method is not available in managed environment
// This method is not available in native environment
text
String to be sent to the terminal session.

Send data to a TCP session. Convert a given string to ANSI and sends it to the session.

send

send(byte: number): void;
// This method is not available in managed environment
// This method is not available in native environment
byte
A single byte to be sent to the terminal session.

Send a given byte to a TCP session.

send

send(bytes: number [] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView): void;
// This method is not available in managed environment
// This method is not available in native environment
bytes
A JavaScript array of integer numbers to be sent to the terminal session. Each number is treated as an unsigned 8-bit value.

Send given byte array to a TCP session.

Send data to the terminal session

// Send ASCII string to the TCP endpoint
session.send("AT\n");

// Send a single byte to the TCP endpoint
session.send(0x0d);

// Send a byte array to the TCP endpoint
session.send([ 0x41, 0x54, 0x0d ]);

receive

receive(): Promise<Uint8Array>;
// This method is not available in managed environment
// This method is not available in native environment

Starts a receive operation on a network session. This method returns a promise that yields a byte array when completed.

Receive data from the network

async function read(session: ITcpSession)
{
    while (true)
    {
        try
        {
            var data = await session.receive();
            // process data (Uint8Array)
        } catch(e)
        {
            // network error occurred
        }
    }
}