websocket二进制框架示例
在互联网上,我找不到任何使用 Javascript(作为 Web 客户端)和 Java(作为 Web 服务器)进行“websocket 二进制框架”通信的示例。
你能发布一些“websocket 二进制框架”通信的例子吗?
In Internet, I could not found any example for "websocket binary frame" communication using Javascript (as web client) and Java (as web server).
Can you anybody post few example for "websocket binary frame" communication ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Kaazing WebSocket Gateway 已经提供二进制支持很长一段时间了。此外,它也适用于本身不支持 WebSocket 的旧版浏览器。并且还支持 JavaScript 以外的客户端。因此,您可以使用 JavaScript、Flash/Flex、Silverlight、.Net 或 Java 通过 WebSocket 进行二进制处理。您可以使用任何浏览器,后备模拟将在较旧的浏览器中运行。
后端服务器可以是 Java 或任何侦听 TCP 端口的服务器。
Kaazing WebSocket Gateway has had binary support for quite a while now. Moreover it also works in older browsers that don't support WebSocket natively. And there is support for clients other than JavaScript. So you can do binary over WebSocket using JavaScript, Flash/Flex, Silverlight, .Net, or Java. You can use any browser, the fallback emulation will work in older browsers.
The backend server can be Java or anything that listens on a TCP port.
Jetty 至少从 7.5.2 版本开始就支持 WebSocket 中的二进制帧。下面是一个包含二进制帧的 Jetty 示例: https://www.eclipse.org/jetty/documentation/9.4.x/jetty-websocket-api-send-message.html
从服务器角度来看,有很发送和接收二进制数据之间没有什么区别,只是一个操作码的变化。发送文本时,您只能使用 UTF-8 编码的数据。使用二进制就没有这个限制。
从浏览器的角度来看,如果浏览器支持二进制数据(实际上只有最新版本的 Chrome 支持),那么发送二进制数据涉及使用 WebSocket 上的
send()
方法发送 arraybuffer 或 blob目的。如果服务器发送二进制帧,则会自动接收二进制数据。但是,您可以通过在 WebSocket 对象实例上设置binaryType
属性来选择接收 Blob 或数组缓冲区。Jetty has supported binary frames in WebSockets since at least version 7.5.2. Here is a Jetty example that includes binary frames: https://www.eclipse.org/jetty/documentation/9.4.x/jetty-websocket-api-send-message.html
From the server point of view, there is very little difference between sending and receiving binary data, it's just a single opcode change. When sending text, you are limited to UTF-8 encoded data. With binary you don't have that limit.
From the browser point of view, if the browser supports binary data (which really only very recent builds of Chrome support) then sending binary data involves sending an arraybuffer or blob using the
send()
method on the WebSocket object. Receiving binary data happens automatically if the server sends a binary frame. However, you can select between receiving blobs or arraybuffers by setting thebinaryType
property on your WebSocket object instance.我只知道如何解开从浏览器发送的内容,这是我的代码:
从这里找到: http:// Songpengfei.iteye.com/blog/1178310
链接中有一个压缩的c源代码,我将其更改为node。现在我正在研究如何向客户端发送数据。
I just know how to unwrap the content sent from browser, here is my code:
Found from here: http://songpengfei.iteye.com/blog/1178310
Link there is a zipped c source code, I change it to node. And now I'm study how to send data to the client.