HTML and CSS Reference
In-Depth Information
wsConnection.onmessage = function (msg) {
//write message
chatBox.value = chatBox.value + "Them: " +;
//helper functions.
function NewLine()
chatBox.textContent = chatBox.textContent + '\r\n';
<div align="center">
70-480 Study Group Chat Forum
<textarea id="chatWindow" style="height: 500px; width: 300px">
<input type="text" id="msgSendText" style="width: 300px"/>
<button id="Disconnect">Disconnect</button>
<button id="Connect">Connect</button>
<button id="Send">Send</button>
The primary object that you will work with is the WebSocket object, which connects to the
socket when its constructor is invoked. In Listing 2.1, a variable is declared but not instanti-
ated until a user invokes the connect button. When the user clicks the button, the WebSocket
is instantiated with the appropriate connection information:
wsConnection= new WebSocket('ws://', ['soap', 'xmpp']);
The WebSocket constructor accepts two parameters:
The URL of the server-side socket to connect to, which is always prefixed with ws or
wss for secure WebSocket connections
An optional list of subprotocols
When the WebSocket constructor is called, the WebSocket API establishes a connection
to the server. One of two things can happen at this stage. The WebSocket will successfully
connect to the server or the connection will fail, resulting in an error. Both cases should be
Search WWH ::

Custom Search