简体   繁体   English

如何通过JavaScript通过TCP套接字进行通信?

[英]How can I communicate over TCP sockets from JavaScript?

I'm thinking about how limiting it is for AJAX apps to have to poll for updates, when what would be ideal is for javascript to be able to set up a real two way connection to the server. 我正在考虑限制它是如何限制AJAX应用程序必须轮询更新,当什么是理想的是javascript能够建立一个真正的双向连接到服务器。 I'm wondering if there is some method of integrating javascript with a browser plugin that can make a tcp connection so that I could pass data into and out of the browser plugin. 我想知道是否有一些方法可以将javascript与可以建立tcp连接的浏览器插件集成,以便我可以将数据传入和传出浏览器插件。

WebSockets旨在解决此问题。

Here is an implementation with a similar approach: 这是一个采用类似方法的实现:

It uses a Java Applet and bridges its API to JavaScript, interesting... 它使用Java Applet并将其API连接到JavaScript,有趣......

And here another one: 还有一个:

This one is a wrapper of the Actionscript 3 Socket API, bridged to JavaScript... 这是一个ActionScript 3 Socket API的包装器,桥接到JavaScript ...

You can use node.js framework's socket.io package which can can be installed via npm (A node package manager). 您可以使用node.js框架的socket.io包,它可以通过npm (节点包管理器)安装。

More detailed usage . 更详细的用法

jSocket and Stream are two options that utilize Flash's built-in XML sockets, though neither appears to be production-ready. jSocketStream是使用Flash的内置XML套接字的两个选项,尽管它们似乎都不是生产就绪的。 I'd lean towards using a Flash-based solution rather than Java, as browser penetration is higher and generally offers a better user experience (load times & stability). 我倾向于使用基于Flash的解决方案而不是Java,因为浏览器渗透率更高,并且通常提供更好的用户体验(加载时间和稳定性)。

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

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