• new Server(pakettoInstance?
, preallocateBytes?
, ...transports
)
Creates a new server.
Name | Type | Description |
---|---|---|
pakettoInstance |
PakettoInstance |
The paketto instance to use. Defaults to a new instance. |
preallocateBytes |
number |
The number of bytes to preallocate for the packet buffer. Defaults to 1MB (1024 * 1024). |
...transports |
ITransport [] |
The transports to use. If none are provided, a WebSocketTransport with port 3000 will be used. |
• Optional
onConnect: (client
: SocketClient
) => void
▸ (client
): void
Called when a client connects to the server.
Name | Type | Description |
---|---|---|
client |
SocketClient |
The client that connected. |
void
• get
buffer(): Uint8Array
Uint8Array
• get
clients(): Map
<number
, SocketClient
>
Returns a list of clients. This is a copy of the internal list, so modifying it will not affect the server.
Map
<number
, SocketClient
>
• get
nextConnectionId(): number
Gets the next connection ID.
number
• get
paketto(): PakettoInstance
PakettoInstance
• get
transports(): Set
<ITransport
>
Returns a list of transports. This is a copy of the internal list, so modifying it will not affect the server.
Set
<ITransport
>
▸ broadcast(event
, data
): void
Broadcasts a message to all connected clients.
Name | Type | Description |
---|---|---|
event |
unknown |
The event identifier. |
data |
unknown |
The data to send. |
void
▸ start(): void
Starts the server.
void
▸ stop(): void
Stops the server.
void