HTML and CSS Reference
In-Depth Information
function displayMsg(msg) {
var o=document.getElementById("chat1");
o.innerHTML=o.innerHTML+"<p><b>Agent:</b>"+msg+"</p>";
};
</script>
This code is similar to the JavaScript on the Agent application. The connect() function gets a WebSocket
and sends the initial sign-on message and then wires-up the onmessage and onclose event handlers. The send()
function sends the text that was entered to the server and echoes it on the page. The displayMsg() function is the
event handler for the processing incoming messages from the server, which are displayed on the page.
Testing the Solution
Earlier in the chapter, you setup the WsServer and the Client projects to both start when debugging. Now you'll
need to add the Agent application as well. Then you will debug all three applications at the same time.
eXerCISe 13-8. teStING the SOLUtION
1.
right-click the Chapter 13 solution and select the “Set StartUp projects” link. In the
dialog box, change the action for the Agent application to Start. Also move this down
to be the second project loaded.
2.
press F5 to debug the applications. You should see the console app as well as two
browser windows. Go to the Agent page. If not already logged in, log in now. You
should only have to register once. After that you just log in.
3.
Click the begin Chat link, which should display the new chat page, and show that
you are connected to the server.
4.
Go to the Client page, enter a name, and click the Chat now button. You should get a
response in the chat windows as illustrated in Figure 13-15 .
 
Search WWH ::




Custom Search