Skip to main content

LensStudio:Network.BaseServer

Class

Base class for network servers, providing common listen and connection management functionality.

Index

Example

// BaseServer is the base class for network servers. Use TcpServer as a
// concrete subclass to demonstrate listen(), close(), onConnect, onError.
const server = TcpServer.create();
this.server = server;

this.connections.push(
server.onConnect.connect((socket) => {
console.log('Client connected from:', socket.remoteAddress.address);
})
);
this.connections.push(
server.onError.connect((code: number) => {
console.log('Server error code:', code);
})
);

const addr = new Address();
addr.address = '127.0.0.1';
addr.port = 0;
const ok = server.listen(addr);
console.log('Server listening:', ok, 'on port:', server.port);

Extends

Extended by

Properties

address

readonly address: string

The address string the server is currently bound to.


onConnect

readonly onConnect: signal1<BaseSocket, void>

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


onError

readonly onError: signal1<number, void>

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


port

readonly port: number

Port number the server is currently bound to.

Methods

close()

close(): void

Closes the server and stops accepting new connections.

Returns

void


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


listen()

listen(address): boolean

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

Parameters

ParameterType
addressAddress

Returns

boolean