WebSocketServer class

A WebSocket server that listens for client connections and handles messages.

This class provides methods to start and stop a WebSocket server, handle client connections, receive messages, and broadcast messages to all connected clients. It also allows sending messages to specific clients and handling commands received from clients using a callback function.

Constructors

WebSocketServer({int port = 8080, required void cmdCallBackFunction(String message), required void fileCallBackFunction(dynamic data), required void clientsListCallBack(List<WebSocket> clients)})
Constructor for WebSocketServer that initializes the server with a port and callback functions.

Properties

clientsListCallBack → void Function(List<WebSocket> clients)
final
cmdCallBackFunction → void Function(String message)
A callback function that is invoked when a message is received from any client.
final
fileCallBackFunction → void Function(dynamic data)
final
hashCode int
The hash code for this object.
no setterinherited
port int
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

broadcastMessage(String message, WebSocket sender) → void
Broadcasts a message to all connected clients except the sender.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendFileToClient(String filePath) Future<bool>
sendMessage(String message) → void
Sends a message to all connected clients.
start() Future<void>
Starts the WebSocket server and begins listening for connections.
stop() Future<void>
Stops the WebSocket server and disconnects all clients.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited