Peter Himschootpeter@u2u.netU2U
“Real time web” is                             awesome!!!“A real pain to build”
Ian Hickson
Server          Client          Server“Comet”           Client
a socket that works anywhere across the web…even through network intermediaries
public class GameHttpHandler : IHttpHandler{  public void ProcessRequest(HttpContext context)  {    if (context.IsWebSocke...
public async Task SocketReceiver(AspNetWebSocketContext context){  var socket = context.WebSocket as AspNetWebSocket;  var...
public async Task SendMessage(SocketMessage message){  string json = JsonConvert.SerializeObject(message);  var buffer = n...
“ws://servername/socket”                              “wss://servername/socket”var ws = new WebSocket(socketUri);ws.openSt...
ws.onopen = function () {  display(Connected);}ws.onmessage = function (json) { processMessage(json);}...
ws.send(JSON.stringify({ type: "wins", player: player }));
Demo
http://aka.ms/mbl-techhttp://aka.ms/mbl-tech/devprevhttp://aka.ms/mbl-tech/html5
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Building real-time apps with WebSockets
Upcoming SlideShare
Loading in...5
×

Building real-time apps with WebSockets

2,972

Published on

WebSockets is an emerging standard that enables real-time and bidirectional communication across the Web. You will learn how HTML5 web applications can make dramatic improvements in terms of user experience and performance by taking advantage of this technology. In this session we will focus on the new WCF 4.5 and ASP.NET 4.5 APIs supporting this standard.

Published in: Technology, News & Politics
1 Comment
0 Likes
Statistics
Notes
  • Hi,
    Could I program a video chat via web socket? I'm trying to look for some way, but up to now, i haven't been able to do it.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total Views
2,972
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
28
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  • Scalability issuesProgramming modelCOMET technique (http://en.wikipedia.org/wiki/Comet_(programming)) Long PollingHidden iFrame
  • Nicer way to do what we are doing today (Fb, twitter)New stuff that you can’t do todayNetwork intermediariesProxys Firewalls Gateways
  • Building real-time apps with WebSockets

    1. 1. Peter Himschootpeter@u2u.netU2U
    2. 2. “Real time web” is awesome!!!“A real pain to build”
    3. 3. Ian Hickson
    4. 4. Server Client Server“Comet” Client
    5. 5. a socket that works anywhere across the web…even through network intermediaries
    6. 6. public class GameHttpHandler : IHttpHandler{ public void ProcessRequest(HttpContext context) { if (context.IsWebSocketRequest) { var player = new GamePlayer(); FourInABruGame.Join(player); context.AcceptWebSocketRequest(player.SocketReceiver); } }
    7. 7. public async Task SocketReceiver(AspNetWebSocketContext context){ var socket = context.WebSocket as AspNetWebSocket; var buffer = new ArraySegment<byte>(new byte[2048]); while (true) { var message = await socket.ReceiveAsync(buffer, CancellationToken.None); // Convert to JSON var json = Encoding.UTF8.GetString(buffer.Array, 0, message.Count); var test = new { type = "" }; test = JsonConvert.DeserializeAnonymousType(json, test);
    8. 8. public async Task SendMessage(SocketMessage message){ string json = JsonConvert.SerializeObject(message); var buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(json)); await Context.WebSocket.SendAsync(buffer, WebSocketMessageType.Text, endOfMessage: true, cancellationToken: CancellationToken.None);}
    9. 9. “ws://servername/socket” “wss://servername/socket”var ws = new WebSocket(socketUri);ws.openStateConst = WebSocket.OPEN;
    10. 10. ws.onopen = function () { display(Connected);}ws.onmessage = function (json) { processMessage(json);}...
    11. 11. ws.send(JSON.stringify({ type: "wins", player: player }));
    12. 12. Demo
    13. 13. http://aka.ms/mbl-techhttp://aka.ms/mbl-tech/devprevhttp://aka.ms/mbl-tech/html5
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×