HTML and CSS Reference
In-Depth Information
Chapter 13
As I explained back in Chapter 1 , the web application pulls data from a web server. The client initiates the transfer
by sending a request to the server. The response is then rendered in the browser. All web application design
is based on this request/response paradigm. However, WebSocket technology opens up a whole new world,
allowing server-initiated communication with client applications.
Socket technology is not new. Sockets have been used for decades as an effective protocol for point-to-point
communication between applications. The exciting news, however, is that the W3C has included a WebSocket
API specification as part of the HTML5 umbrella. With a standard protocol defined, and compatible browsers
becoming available, you can expect to see more and more web applications taking advantage of this technology.
In this chapter you will build a solution that uses websockets to implement a multi-session chat application
that enables an agent to chat with several customers at the same time. This solution will include a websocket
server hosted in a console app that you will create using C# .NET. To do this you'll need to understand the
websocket protocols so I will first explain this technology and then show you how to create your own custom
server. You will then implement both the agent and customer client applications utilizing the native websocket
support in HTML5.
As of this writing, the W3C specification was still in draft and changes are likely. It is perhaps a bit
premature to jump into this wholeheartedly. However, since this is such a promising part of the HTML5 specification
I wanted to introduce you to websockets. Just be aware that things can change. You can check out the current status
of the W3C specification here: . All major current browsers support
websockets except IE9, however, they don't all support the same protocol versions, which I'll address later.
Understanding WebSockets
Sockets provide a mechanism for two-way transmissions between applications, including peer-to-peer
communication. WebSockets, as I will explain in this chapter, are a specific implementation of sockets, that
enable a web application to communicate with a web server. The messages passed between the browser and
server are illustrated in Figure 13-1 . After a series of handshaking messages that establish the connection, both
sides can send messages to each other.
Search WWH ::

Custom Search