`
xumingyong
  • 浏览: 175427 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Websocket定义

阅读更多

 

看看W3C在HTML5里对于WebSocket的接口定义:

 

interface WebSocket {
  readonly attribute DOMString URL;

  // ready state
  const unsigned short CONNECTING = 0;
  const unsigned short OPEN = 1;
  const unsigned short CLOSED = 2;
  readonly attribute unsigned short readyState;
  readonly attribute unsigned long bufferedAmount;

  // networking
           attribute Function onopen;
           attribute Function onmessage;
           attribute Function onclose;
  boolean send(in DOMString data);
  void close();
};
WebSocket implements EventTarget;

Web Sockets Now Available In Google Chrome

 

Wednesday, December 09, 2009

Labels: html5, webkit, websockets

 

Starting in the Google Chrome developer channel release 4.0.249.0, Web Sockets are available and enabled by default. Web Sockets are "TCP for the Web," a next-generation bidirectional communication technology for web applications being standardized in part ofWeb Applications 1.0. We've implemented this feature as described in our design docs forWebKit and Chromium.
The Web Sockets API enables web applications to handle bidirectional communications with server-side process in a straightforward way. Developers have been using XMLHttpRequest("XHR") for such purposes, but XHR makes developing web applications that communicate back and forth to the server unnecessarily complex. XHR is basically asynchronous HTTP, and because you need to use a tricky technique like long-hanging GET for sending data from the server to the browser, simple tasks rapidly become complex. As opposed toXMLHttpRequest, Web Sockets provide a real bidirectional communication channel in your browser. Once you get a Web Socket connection, you can send data from browser to server by calling a send() method, and receive data from server to browser by an onmessage event handler. A simple example is included below.
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.
}
In addition to the new Web Sockets API, there is also a new protocol (the "web socket protocol") that the browser uses to communicate with servers. The protocol is not raw TCP because it needs to provide the browser's "same-origin" security model. It's also not HTTP because web socket traffic differers from HTTP's request-response 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. To use this new API and protocol and take advantage of the simpler programming model and more efficient network traffic, you do need a new server implementation to communicate with — but don't worry. We also developed pywebsocket, which can be used as an Apache extension module, or can even be run as standalone server.
You can use Google Chrome and pywebsocket to start implementing Web Socket-enabled web applications now. We're more than happy to hear your feedback not only on our implementation, but also on API and/or protocol design. The protocol has not been completely locked down and is still in discussion in IETF, so we are especially grateful for any early adopter feedback.
分享到:
评论

相关推荐

    websocket连接两个页面,一个页面控制另外一个页面跳转。

    大客户端可以发送消息到小客户端,并且大客户端可以发送“jump”命令到小客户端控制小客户端页面跳转到百度。其中系统管理页面记录所有大端与小端发送的消息,以及大端与小端的id。

    websocket_for_linux-master_websocket_websocket客户端_WEBSOCKET单片机实现

    5WebSocket 使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据。在 WebSocket API 中,...HTML5 定义的 WebSocket 协议,能更好的节省服务器资源和带宽,并且能够更实时地进行通讯。

    websocket实现前后台数据更新

    websocket.js,websocket页面使用javascript文件,定义.onopen、onmessage、onclose、onerror函数,html通过调用 openSocket(userId)函数,建立websocket链接;其中userId必须唯一; 3、后端代码 WebSocketServer....

    websocket-cluster:这是一个针对WebSocket集群服务器的Spring Cloud项目。

    网关做请求转发时,会通过我们重新定义的自定义负载均衡过滤。器,根据业务上需要哈希的分区来实现真实路由器的路由。技术栈Docker(开启API访问) 雷迪斯兔子MQ 纳科斯本地开发为创建一个专用网络: docker network...

    详解微信小程序实现WebSocket心跳重连

    RFC6455 定义了它的通信标准。 WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议。 为什么需要Websocket HTTP 协议是一种无状态的、无连接的、单向的应用层协议。它采用了请求/响应模

    websocket 推送图像 Js显示

    通过WebSocket实现服务器主动推送 图像数据通过Base64编码,定义为Json格式传输 前端收到Json数据后 将图像还原 代码有任何问题可以和我联系 liangji@csu.ac.cn 一起学习,此外也可以看我的博客 博客有更详细的介绍...

    websocket.js 页面websocket通信用js

    websocket.js,websocket页面使用javascript文件,定义.onopen、onmessage、onclose、onerror函数,html通过调用 openSocket(userId)函数,建立websocket链接;其中userId必须唯一;

    WebSocket图文解析

    1. 介绍websocket的定义:实现客户端和服务器端的全双工实时通信,客户端可以给服务器发信息,服务器也可以直接给客户端发信息。而HTTP智能客户端给服务器发信息,服务器不能主动给客户端发信息; 2. websocket 优点...

    PHP的WebSocket类库php-ws.zip

    实现基于Websocket 协议的 PHP类库 和 javascript类库 , 实现事件 回调函数的架构开发,以一个简单聊天室实例介绍其使用方法: 不同浏览器,不同电脑,不同地域, 实时通讯。实现的详细 请研究源码。 /***服务端*...

    javafx-websocket-test:从 JavaFX 客户端使用 WebSocket 的示例项目

    WebSocket 端点定义为带注释的端点,如规范中所述 。 为每个通信任务创建一个新的服务器连接(即连接资源不在任务之间共享或重用)。 此实现不知道代理。 有关使系统代理感知的信息,请参阅。 对于高流量通信,...

    WebSocket推送端和接收端实现

    运行时先启动WebSocketUtil类(消息推送端/服务端),再启动SocketClient(消息接收端/客户端),如需自定义消息协议可以在发送端的writeMessage方法中定义发送协议,在接收端onMessage方法中定义接收协议。...

    websocket-4.0.5.RELEASE.jar

    在浏览器中通过http仅能实现单向的通信,comet可以一定程度上模拟双向通信,但效率较低,...面对这种状况,HTML5定义了WebSocket协议,能更好的节省服务器资源和带宽并达到实时通讯。 在JavaEE7中也实现了WebSocket协议。

    Django的WebSocket支持dwebsocket.zip

    这个模块实现了在RFC 6455中定义的WebSocket协议的最终版本。某些浏览器版本(特别是Safari 5. x)实现早期的草案协议(称为“76草案”)和与该模块不兼容。 dwebsocket模块基于django-websocket发展,但是目前...

    websocket-extensions-node:WebSocket连接的通用扩展管理

    该库旨在通过定义允许模块进行协作的帧和消息的抽象表示,来允许WebSocket扩展与任何协议库一起编写和使用。 websocket-extensions提供了一个用于注册扩展插件的容器,并提供了通过Sec-WebSocket-Extensions标头...

    websocket-server 简单的一个例子

    WebSocket使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据。...在这种情况下,HTML5定义了WebSocket协议,能更好的节省服务器资源和带宽,并且能够更实时地进行通讯

    java-websocket-reverse-proxy:Websocket反向代理的Java实现

    java-websocket-reverse-proxy 我发现的大多数Java websocket示例都是基于或包含诸如STOMP之类的消息传递协议的。... 可以通过运行进行测试文件夹中定义的类中包含一个与该代理行为匹配的简单Java实现。

    jmeter-websocket-samplers:JMeter插件,用于对WebSocket应用程序进行负载测试

    JMeter WebSocket采样器JMeter附加组件,它定义了许多用于负载测试WebSocket应用程序的采样器。用法从目录下载jar,将其复制到/ lib / ext并启动JMeter。 就这样。 您也可以使用jmeter-plugins安装插件。 如果您使用...

    bash-websocket-client:用 bash 编写的 Websocket 客户端

    send_to_websocket.sh - 这将打开一个连接并将其 CLI 参数发送到脚本中定义的服务器。 用法: ./send_to_websocket.sh "MY AWESOME MESSAGE" websocket_echo_example.sh - 这是一个交互式脚本,它将打开与的连接并...

    WebSocket编程

    WebSocket 是一种网络通信协议。RFC6455 定义了它的通信标准。 WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议。

    WebSocketDemo( C#+Html源码)

    WebSocketDemo,实现网页与后台的通讯。 WebSocket 是一种网络通信协议。RFC6455 定义了它的通信标准。 WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议。

Global site tag (gtag.js) - Google Analytics