Websocket protocol overview
Upcoming SlideShare
Loading in...5
×
 

Websocket protocol overview

on

  • 6,696 views

Websocket protocol overview and implement

Websocket protocol overview and implement

Statistics

Views

Total Views
6,696
Views on SlideShare
3,825
Embed Views
2,871

Actions

Likes
5
Downloads
92
Comments
0

8 Embeds 2,871

http://blog.allenm.me 2794
http://feed.feedsky.com 51
http://cache.baidu.com 14
https://twitter.com 6
http://translate.googleusercontent.com 3
http://zhuaxia.com 1
http://xianguo.com 1
http://webcache.googleusercontent.com 1
More...

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Websocket protocol overview Websocket protocol overview Presentation Transcript

  • The way to HTML5
  • The way to HTML5
  • FD
  • FD $.ajax(‘http://localhost/do_sth/’,{ ‘type’:‘GET’, ‘dataType’:‘json’, ‘success’:function(data){ console.log(data); } });
  • var ws_uri = "ws://localhost:9999";if ("WebSocket" in window) { webSocket = new WebSocket(ws_uri);}else if("MozWebSocket" in window) { // Firefox 7/8 webSocket = new MozWebSocket(ws_uri);}webSocket.onmessage = function(e) { console.log("Got echo: " + e.data);}
  • HTTPdebug, WPO
  • HTTP debug, WPOWebSocketHTTP
  • HTTP debug, WPOWebSocketHTTP new WebSocket(ws_uri)
  • WebSocket protocol protocolWebSocket server
  • WebSocket API
  • WebSocket API API WebSocket
  • WebSocket API API WebSocketvar ws_uri = "ws://localhost:9999";webSocket = new WebSocket(ws_uri);webSocket.onmessage = function(e) { console.log("Got echo: " + e.data);}
  • WebSocket APIWebSocket API WebSocket Protocol
  • WebSocket Protocol 10 chrome 14+ , firefox 7+chrome blog
  • WebSocket Protocol 10 chrome 14+ , firefox 7+chrome blog
  • WebSocket Protocoloverview: “ ” API onmessage API
  • WebSocket Protocoloverview: frame frame message frame message frame message
  • WebSocket Protocoloverview: frame WebSocket Protocol raw data, raw data message ( control frame )
  • WebSocket ProtocolHandShake:
  • WebSocket ProtocolHandShake: GET WebSocket HTTP Header origin , WebSocket Version , WebSocket Key , Cookies Connection: Upgrade Upgrade: websocket WebSocket
  • WebSocket ProtocolHandShake: HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade: websocket websocket
  • WebSocket ProtocolHandShake: Sec-WebSocket-Protocol: chat subprotocol为
  • WebSocket ProtocolHandShake: Sec-WebSocket-Origin: http://work server
  • WebSocket ProtocolHandShake: Sec-WebSocket-Origin: http://work server Sec HTTP Header javascript
  • WebSocket ProtocolHandShake: server client client websocket hankshake XHR form
  • WebSocket ProtocolHandShake: server HandShake HTTP header Sec-WebSocket-key, "258EAFA5-E914-47DA-95CA- C5AB0DC85B11" SHA-1 hash , base64-encode , Response Header “Sec-WebSocket-
  • WebSocket ProtocolHandShake: WebSocket Pythongit checkout handshake
  • WebSocket Protocolframe :
  • WebSocket Protocolframe :
  • WebSocket Protocolframe : FIN 1bit, message RSV0 RSV1 RSV2 1bit, 0 opcode: 4bit, payload data
  • WebSocket Protocolframe : FIN 1bit, message RSV0 RSV1 RSV2 1bit, 0 opcode: 4bit, payload data
  • WebSocket Protocol frame :opcode * %x0 denotes a continuation frame FIN 1bit, message * %x1 denotes a text frame * %x2 denotes a binary frame RSV0 RSV1 RSV2 1bit, * %x3-7 are reserved for further non-control frames 0 * %x8 denotes a connection close * %x9 denotes a ping opcode: 4bit, payload data * %xA denotes a pong * %xB-F are reserved for further control frames
  • WebSocket Protocolframe : mask: 1bit , payload data 1 masking-key 1 payload length: 7 bits , 7+16bits , or 7+64 bits 7bit 0 -125 126 2byte 127 4byte Masking-Key: 0 or 4 bytes. mask 0 key 0 mask 1 key 4 bytes
  • WebSocket Protocolframe : Payload data: (x+y)bytes , payload data Extension data: x bytes, 0 Application data: y bytes , payload data
  • WebSocket Protocolframe : WebSocket server frame
  • WebSocket Protocolmore : http:// tools.ietf.org/html/draft-ietf-hybi- thewebsocketprotocol-10
  • Python: AutobahnNode.js : http://socket.io/#homeRuby : https://github.com/gimite/web-socket-rubyJava: https://github.com/TooTallNate/Java-WebSocket
  • Q&A