LensStudio:Network.BaseServer
ClassBase 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
readonlyaddress:string
The address string the server is currently bound to.
onConnect
readonlyonConnect:signal1<BaseSocket,void>
Signal fired when a new client socket connects to the server.
onError
readonlyonError:signal1<number,void>
Signal fired when a server error occurs, passing an error code.
port
readonlyport:number
Port number the server is currently bound to.
Methods
close()
close():
void
Closes the server and stops accepting new connections.
Returns
void
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
listen()
listen(
address):boolean
Starts listening for incoming connections on the specified address; returns true if successful.
Parameters
| Parameter | Type |
|---|---|
address | Address |
Returns
boolean