Preparing search index...

    A class to accept TCP connetions. Useful for receiving streaming data. It's also able to send back responses.

        // TcpServer extends BaseServer and accepts incoming TCP connections.
    // Create one via the static create() method, configure an Address, then listen.
    const { TcpServer, Address } = await import('LensStudio:Network');

    const server = TcpServer.create();
    console.log('Created TcpServer instance');

    // Configure the address to listen on
    const addr = new Address();
    addr.address = '127.0.0.1';
    addr.port = 0; // OS picks an available port
    console.log('Configured address:', addr.address, 'port:', addr.port);

    // Start listening
    const listening = server.listen(addr);
    console.log('Server listening:', listening);
    console.log('Bound address:', server.address);

    // onConnect fires when a client connects
    this.connections.push(
    server.onConnect.connect((socket: import('LensStudio:Network').BaseSocket) => {
    console.log('Client connected');
    })
    );

    // onError fires on server errors
    this.connections.push(
    server.onError.connect((errorCode: number) => {
    console.log('Server error, code:', errorCode);
    })
    );

    // Clean up by closing the server
    server.close();
    console.log('TcpServer closed');

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    address: string

    The address string the server is currently bound to.

    onConnect: signal1<BaseSocket, void>

    Signal fired when a new client socket connects to the server.

    onError: signal1<number, void>

    Signal fired when a server error occurs, passing an error code.

    port: number

    Methods

    • Closes the server and stops accepting new connections.

      Returns void

    • Returns the name of this object's type.

      Returns string

    • Returns true if the object is of the specified type.

      Parameters

      • type: string

      Returns boolean

    • Starts listening for incoming connections on the specified address; returns true if successful.

      Parameters

      Returns boolean