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
connect(hostName: string, port: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
hostName
port
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(): void;
// This method is not available in managed environment
// This method is not available in native environment
Stop the running TCP session.
send(text: string): void;
// This method is not available in managed environment
// This method is not available in native environment
text
Send data to a TCP session. Convert a given string to ANSI and sends it to the session.
send(byte: number): void;
// This method is not available in managed environment
// This method is not available in native environment
byte
Send a given byte to a TCP session.
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
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(): 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
}
}
}