HTML and CSS Reference
In-Depth Information
Figure 11-9. Web Form acting as a Web Socket client
As you can see, the Web Socket client web form consists of a text box and a button. The user enters
some data in the text box and clicks the Send button. The Web Socket server sitting on IIS 8.0 listens to the
incoming communication, receives the data sent by the client, and echoes it back to the client. The echoed
data is displayed on the web form by appending it to a <div> element.
n Note Although you can develop this application using Visual Studio 2012 installed on Windows 7, you won't be
able to run and test it. To run the example, you need Windows 8 with IIS 8.0 installed. You must also enable the
WebSocket protocol in IIS 8.0 if it's not already enabled.
Developing the Echo Server
Before developing the Web Socket client, let's develop the server part. You develop the Echo server as an
ASP.NET generic handler ( .ashx ). The job of the generic handler is to trigger the listening code. Listing 11-
15 shows how this is done.
Listing 11-15. Using a Generic Handler to Start the Echo Server
public class WebSocketGenericHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.IsWebSocketRequest)
{
context.AcceptWebSocketRequest(EchoServer);
}
}
}
 
 
Search WWH ::




Custom Search