Javascript 在没有 node.js 的情况下使用 socket.io 独立
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8182631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using socket.io standalone without node.js
提问by gammay
(JavaScript newbie)
(JavaScript 新手)
I am trying to build a JavaScript based client app that communicates with a server app over socket. I came across socket.io. Is it possible to use socket.io without any node.js dependencies?
我正在尝试构建一个基于 JavaScript 的客户端应用程序,该应用程序通过套接字与服务器应用程序进行通信。我遇到了socket.io。是否可以在没有任何 node.js 依赖项的情况下使用 socket.io?
I have cloned socket.io github and wrote a simple client html to connect to the server (Can post the code if required). But it does not connect to the server.
我已经克隆了 socket.io github 并编写了一个简单的客户端 html 来连接到服务器(如果需要,可以发布代码)。但它没有连接到服务器。
(Background info: We need a simple config client utility that runs on Win32 that communicates with a custom server that supports socket communication with a custom packet-format protocol. Instead of going through the usual MFC/.NET, we think HTML/JS/CSS makes a better solution. For this purpose, I have considered the following options:
(背景信息:我们需要一个在 Win32 上运行的简单配置客户端实用程序,该实用程序与支持使用自定义数据包格式协议的套接字通信的自定义服务器进行通信。我们认为 HTML/JS/ CSS 提供了更好的解决方案。为此,我考虑了以下选项:
- Titanium: Works, but requires runtime to be installed
- HTML5 WebSocket: Not widely supported - works on Chrome but requires IE10
- socket.io: Trying to get it to work
- Any other? (Can post this question as separate thread, if necessary) )
- Titanium:有效,但需要安装运行时
- HTML5 WebSocket:不受广泛支持 - 适用于 Chrome,但需要 IE10
- socket.io:试图让它工作
- 任何其他?(如有必要,可以将此问题作为单独的线程发布))
回答by sbugzu
Establish a successful Socket.IO, your custom server must follow the spec, or use other server implementation of socket.io
https://github.com/learnboost/socket.io/wikithe In other languagespart include some servers implementation of socket.io
建立一个成功的Socket.IO,您的自定义服务器必须遵循的规范,或使用socket.io的其他服务器上执行
https://github.com/learnboost/socket.io/wiki的在其他语言中的部分包括一些服务器实现插座.io
回答by Jason Kim
There's a lot of noise in the answers to the original question. Let me try to answer the question as clear as I can.
原始问题的答案中有很多噪音。让我试着尽可能清楚地回答这个问题。
Is it possible to use socket.io without any node.js dependencies?
是否可以在没有任何 node.js 依赖项的情况下使用 socket.io?
The short answer is yes. You will however have Flash dependency. You can read about how to do this in socket.io's faq.
简短的回答是肯定的。但是,您将拥有 Flash 依赖项。您可以在socket.io 的常见问题解答中了解如何执行此操作。
回答by alex vasi
As I understand, you need a socket.io server without node.js, right? If to use socket.io just as cross-browser WebSockets would be sufficient, and what i mean by that is nicely illustrated in the following example from socket.io web site:
据我了解,您需要一个没有 node.js 的 socket.io 服务器,对吗?如果像跨浏览器 WebSockets 一样使用 socket.io 就足够了,我的意思在 socket.io 网站的以下示例中得到了很好的说明:
var socket = io.connect('http://localhost/');
socket.on('connect', function () {
socket.send('hi');
socket.on('message', function (msg) {
// my msg
});
});
It would make your server code very simple. Surely, you can find some WebSockets library for your language or even write your own. Look at this SOquestion for examples.
它会使您的服务器代码非常简单。当然,您可以为您的语言找到一些 WebSockets 库,甚至可以编写自己的库。看看这个 SO问题的例子。
Or if you want to use socket.io protocolthere is list of socket.io librariesfor different languages, like python and java.
或者,如果您想使用 socket.io协议,则有用于不同语言的 socket.io 库列表,例如 python 和 java。

