LensStudio:WebSocket.WebSocketServer
ClassServer that accepts incoming WebSocket connections and manages connected client sockets.
Index
Example
const WS = await import('LensStudio:WebSocket');
const Network = await import('LensStudio:Network');
const server = WS.WebSocketServer.create();
this.connections.push(
server.onConnect.connect((clientSocket) => {
console.log(`Client connected from ${clientSocket.remoteAddress.address}`);
clientSocket.onData.connect((data) => {
console.log(`Server received: ${data.toString()}`);
});
})
);
const addr = new Network.Address();
addr.address = '127.0.0.1';
addr.port = 9090;
const listening = server.listen(addr);
console.log(`WebSocketServer listening on ${server.address}: ${listening}`);
Extends
Properties
address
readonlyaddress:string
The address string the server is currently bound to.
Inherited from
onConnect
readonlyonConnect:signal1<BaseSocket,void>
Signal fired when a new client socket connects to the server.
Inherited from
onError
readonlyonError:signal1<number,void>
Signal fired when a server error occurs, passing an error code.
Inherited from
port
readonlyport:number
Port number the server is currently bound to.
Inherited from
Methods
close()
close():
void
Closes the server and stops accepting new connections.
Returns
void
Inherited from
create()
staticcreate():WebSocketServer
Creates and returns a new WebSocketServer instance.
Returns
WebSocketServer
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