This post discuss about using WebSockets in ASP.NET 4.5. You can read this post to get an understanding about WebSockets. This post shows piece of code which uses WebSockets in ASP.NET 4.5 and the code is related to simple chat application.

The HTML of Web Form chat application looks as below

It contains a text box where you can type your text message and button where it sends a message to the server. You can notice there is <ul> element which shows the list of other messages which are arriving from the server.

Instantiate a W3C WebSocket JavaScript object and pointed to url to establish a connection to WebSockets Server.

The url starts with ws which runs on HTTP and pointing to .ashx handler which runs on ASP.NET server.