Virtual Serial Port Tools - Advanced serial port configurations for your custom ports usage scenario
Download Virtual Serial Port Tools Hide this button

ISocket Interface

A base interface for both ITcpSocket and IUdpSocket objects.

Declaration

interface ISocket {

    // Methods
    ${connect}(host: string, port: string, timeout?: number): Promise<void>;
    ${close}(): void;
    ${send}(text: string, encoding: ${Common.Encoding} | number): Promise<number>;
    ${send#send1}(byte: number): Promise<number>;
    ${send#send2}(bytes: number[] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView): Promise<number>;
    ${receive}(): Promise<Uint8Array>;
}
// This interface is not available in managed environment
// This interface is not available in native environment

ISocket Methods

connect

connect(host: string, port: string, timeout?: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
host
A host name
port
TCP/UDP port
timeout
Connection timeout, in milliseconds. If omitted or equals zero, the system-wide default TCP connection timeout is used (typically, 20-30 seconds). If not equals zero, the minimum of the specified value and system-wide default will be used. Note that different error code is returned, depending on which timeout occurred first: Win32 ERROR_TIMEOUT for this value and SOCKET_ERROR_CONNECTION_TIMED_OUT for system-wide connection timeout.

Connects the socket to the remote endpoint.

close

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

Closes the active connection.

send

send(text: string, encoding: ${Common.Encoding} | number): Promise<number>;
// This method is not available in managed environment
// This method is not available in native environment

text :

encoding
An optional encoding or Windows code page to use. If omitted, equals to Common.Encoding.Utf8.

The number of bytes sent to the network.

A string to send

Send the given string encoded using the specified encoding to the socket.

send

send(byte: number): Promise<number>;
// This method is not available in managed environment
// This method is not available in native environment
byte
A single byte to send

The number of bytes sent to the network.

Send a single byte to the network.

send

send(bytes: number[] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView): Promise<number>;
// This method is not available in managed environment
// This method is not available in native environment
bytes
An array, typed array, array buffer or DataView object.

The number of bytes sent to the network.

receive

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

A byte array with data received from a socket.

Receive data from a socket.