Web Sockets Now Available In Google Chrome
Web Sockets Now Available In Google Chrome
if ("WebSocket" in window) {
var ws = new WebSocket("ws://example.com/service");
ws.onopen = function() {
// Web Socket is connected. You can send data by send() method.
ws.send("message to send"); ....
};
ws.onmessage = function (evt) { var received_msg = evt.data; ... };
ws.onclose = function() { // websocket is closed. };
} else {
// the browser doesn't support WebSocket.
}
* Web Sockets are "TCP for the Web," a next-generation bidirectional communication technology for web applications being standardized in part of Web Applications 1.0.
* The protocol is not raw TCP because it needs to provide the browser's "same-origin" security model.
* Web socket communications using the new web socket protocol should use less bandwidth because, unlike a series of XHRs and hanging GETs, no headers are exchanged once the single connection has been established.
* We also developed pywebsocket, which can be used as an Apache extension module, or can even be run as standalone server.
WebSocket protocol
The Web Socket protocol is an independent TCP-based protocol. Its
only relationship to HTTP is that its handshake is interpreted by
HTTP servers as an Upgrade request.
Based on the expert recommendation of the IANA, the Web Socket
protocol by default uses port 80 for regular Web Socket connections
and port 443 for Web Socket connections tunneled over TLS.
server side implementation:
* python: pywebsocket
* js: Node.JS and the WebSocket protocol
* go: The Google GO team is working on a WebSocket server
* erlang: Comet is dead long live websockets
Handshake =
[
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n",
"Upgrade: WebSocket\r\n",
"Connection: Upgrade\r\n",
"WebSocket-Origin: http://localhost:2246\r\n",
"WebSocket-Location: ",
" ws://localhost:1234/websession\r\n\r\n"
],
沒有留言:
張貼留言