HTML and CSS Reference
In-Depth Information
The OnMessage event is raised when a client sends data to the server. Inside this
event handler, we can transmit the incoming message to all of the clients, or prob-
ably select only some of them. The process is straightforward. Note that this handler
takes a string named message as a parameter:
socket.OnMessage = () =>
// Display the message on the console.
The Send() method simply transmits the desired message to the specified client.
Using Send() , we can deliver text or binary data across the clients. Let's loop
through the registered clients and transfer the messages to them. We need to modify
the OnMessage event as follows:
socket.OnMessage = () =>
foreach (var client in clients)
// Send the message to everyone!
// Also, send the client connection's unique
identifier in order to recognize who is who.
client.Send(client.ConnectionInfo.Id + "
says: " + message);
Search WWH ::

Custom Search