HTML and CSS Reference
In-Depth Information
"', 'message' :
'" + textView.value + "' }";
socket.send(json);
textView.value = "";
}
}
The server now needs to transmit this message to the clients. Nothing is changed
from the previous chapter:
socket.OnMessage = message =>
{
// Send the text message to everyone!
foreach (var client in clients)
{
client.Send(message);
}
};
The clients decode the JSON string and display the message accordingly. You have
added a prettier presentation style for showing the text in the chat area.
socket.onmessage = function (event) {
if (typeof event.data === "string") {
// Display message.
var jsonObject = eval('(' + event.data +
')');
var userName = jsonObject.name;
var userMessage = jsonObject.message;
chatArea.innerHTML = chatArea.innerHTML +
"<p><strong>" + userName + "</strong>: "
+ userMessage +
"</p>";
}
}
Search WWH ::




Custom Search