简体   繁体   English

在没有node.js的情况下使用socket.io standalone

[英]Using socket.io standalone without node.js

(JavaScript newbie) (JavaScript新手)

I am trying to build a JavaScript based client app that communicates with a server app over socket. 我正在尝试构建一个基于JavaScript的客户端应用程序,它通过套接字与服务器应用程序通信。 I came across socket.io . 我遇到了socket.io Is it possible to use socket.io without any node.js dependencies? 是否可以使用socket.io而没有任何node.js依赖项?

I have cloned socket.io github and wrote a simple client html to connect to the server (Can post the code if required). 我已经克隆了socket.io github并编写了一个简单的客户端html来连接服务器(如果需要可以发布代码)。 But it does not connect to the server. 但它没有连接到服务器。

(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 /不是通过通常的MFC / .NET。 CSS提供了更好的解决方案。为此,我考虑了以下选项:

  1. Titanium: Works, but requires runtime to be installed Titanium:Works,但需要安装运行时
  2. HTML5 WebSocket: Not widely supported - works on Chrome but requires IE10 HTML5 WebSocket:不受广泛支持 - 适用于Chrome但需要IE10
  3. socket.io: Trying to get it to work socket.io:试图让它工作
  4. Any other? 任何其他? (Can post this question as separate thread, if necessary) ) (如果需要,可以将此问题作为单独的帖子发布))

Establish a successful Socket.IO, your custom server must follow the spec , or use other server implementation of socket.io 建立一个成功的Socket.IO,您的自定义服务器必须遵循规范 ,或使用socket.io的其他服务器实现
https://github.com/learnboost/socket.io/wiki the In other languages part include some servers implementation of socket.io https://github.com/learnboost/socket.io/wiki 其他语言部分包括socket.io的一些服务器实现

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? 是否可以使用socket.io而没有任何node.js依赖项?

The short answer is yes. 简短的回答是肯定的。 You will however have Flash dependency. 但是,您将拥有Flash依赖项。 You can read about how to do this in socket.io's faq. 您可以在socket.io的常见问题解答中了解如何执行此操作

As I understand, you need a socket.io server without node.js, right? 据我所知,你需要一个没有node.js的socket.io服务器,对吧? 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: 如果要使用socket.io就像跨浏览器的WebSockets就足够了,我的意思就是在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. 当然,您可以找到适合您语言的WebSockets库,甚至可以自己编写。 Look at this SO question for examples. 看看这个SO问题的例子。

Or if you want to use socket.io protocol there is list of socket.io libraries for different languages, like python and java. 或者如果你想使用socket.io 协议,有不同语言的socket.io库列表 ,如python和java。

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

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