简体   繁体   English

是否有基于浏览器的 Websocket 侦听器实现?

[英]Is there a browser-based Websocket listener implementation?

I am interested to know if anyone has built a javascript websocket listener for a browser.我很想知道是否有人为浏览器构建了 javascript websocket 侦听器。 Basically the server side of a websocket that runs in a client.基本上是在客户端中运行的 websocket 的服务器端。 This would allow messages to be sent to the client directly.这将允许将消息直接发送到客户端。 Why?为什么? Because instead of having a Node.js, python, java, etc, server process sitting on or near the client/browser, I can just use a thread in the browser as a listening server thread.因为不需要在客户端/浏览器上或附近使用 Node.js、python、java 等服务器进程,我可以只使用浏览器中的线程作为侦听服务器线程。 I don't think that any browsers support this currently.我认为目前没有任何浏览器支持这一点。

I've run across answers like this: https://news.ycombinator.com/item?id=2316132我遇到过这样的答案: https : //news.ycombinator.com/item?id=2316132

Just curious if anyone has done this.只是好奇是否有人这样做过。 I believe that the current Websockets spec does not support listeners on the browser.我相信当前的 Websockets 规范不支持浏览器上的侦听器。 It would make the deployment of various peer-to-peer applications a bit easier to deploy.它将使各种对等应用程序的部署更容易部署。

WebRTC allows for peer-to-peer connections to be made between browsers. WebRTC允许在浏览器之间建立对等连接。

You would still need a server in order for individual users to discover each other but then they could connect directly to each other rather than having to pass all their traffic via a central server.您仍然需要一个服务器,以便单个用户能够发现彼此,但随后他们可以直接相互连接,而不必通过中央服务器传递所有流量。

The idea.这个想法。

You can use a simple echo server written in any language.您可以使用以任何语言编写的简单回显服务器 Your script can send the data to the server then get it back, handle it on the same page with different functions/classes emulating the real server.您的脚本可以将数据发送到服务器,然后将其取回,在同一页面上使用模拟真实服务器的不同函数/类来处理它。

An example: http://www.websocket.org/echo.html一个例子: http : //www.websocket.org/echo.html

Then, you can think about different formats of packets to/from server to diffirentiate them inside one script.然后,您可以考虑进出服务器的不同格式的数据包,以在一个脚本中区分它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM