Html 我是否需要服务器才能使用 HTML5 的 WebSockets?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1530023/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:59:59  来源:igfitidea点击:

Do I need a server to use HTML5's WebSockets?

htmlwebsocket

提问by cometta

When using WebSockets, will I need to write server code? In other words, will the JavaScript in my client application need to connect to a specialized server, or will my existing Apache server work to support this?

使用 WebSockets 时,是否需要编写服务器代码?换句话说,我的客户端应用程序中的 JavaScript 是否需要连接到专门的服务器,或者我现有的 Apache 服务器是否可以支持这一点?

采纳答案by Rafa

The server has to support web sockets. After a first handshake in HTTP, the server and the client open a socket connection. The server must be able to understand and accept this handshake.

服务器必须支持网络套接字。在 HTTP 中的第一次握手之后,服务器和客户端打开一个套接字连接。服务器必须能够理解并接受此握手。

In my last project we run quite successfully web socket connections using the last Jetty version.

在我的上一个项目中,我们使用最新的 Jetty 版本非常成功地运行了 Web 套接字连接。

27/02/2014: Now I'm also implementing websockets under .net with XSockets.net and works like a charm, you don't even need a web server (self hosting). The WebSocket implementation of ASP.NET works also quite good.

27/02/2014:现在我也在 .net 下使用 XSockets.net 实现 websockets 并且工作起来很迷人,你甚至不需要网络服务器(自托管)。ASP.NET 的 WebSocket 实现也很好。

回答by ShahRokh

Yes,you need to write server code.

是的,您需要编写服务器代码。

I recommend another web socket server based on php: ratchet. And this linkis benchmarking webSocket servers between ratchet and sockJS.

我推荐另一个基于 php 的网络套接字服务器:ratchet。这个链接正在对棘轮和 sockJS 之间的 webSocket 服务器进行基准测试。

Complete list of client & server side codes and browsers support please check this link

客户端和服务器端代码和浏览器支持的完整列表请查看此链接

回答by Kerry Jiang

Of course you need a WebSocket server. But there are many free websocket server in different language, like jWebSocket in Java and SuperWebSocketin .NET, you can use them directly.

当然你需要一个 WebSocket 服务器。但是有很多不同语言的免费 websocket 服务器,比如 Java 中的jWebSocket和 .NET 中的SuperWebSocket,你可以直接使用它们。

回答by AlexC_JEng

There are some plugins currently being developed on google code for Apache...

目前有一些插件正在为 Apache 的谷歌代码开发......

By definition websockets like normal sockets are client-server so yes, you need a server. However there is an alternative to waiting for Apache plugins.

根据定义,像普通套接字一样的 websocket 是客户端-服务器,所以是的,你需要一个服务器。但是,除了等待 Apache 插件之外,还有一种选择。

I am using a hosted server http://www.achex.ca. Its free and you have tutorials in javascript on how to use the server. A good start for websockets development.

我正在使用托管服务器http://www.achex.ca。它是免费的,你有关于如何使用服务器的 javascript 教程。websockets 开发的良好开端。

The server is basically a message router and you can connect to it and use it as a meeting point for all your websocket clients.

服务器基本上是一个消息路由器,您可以连接到它并将其用作所有 websocket 客户端的会面点。

Short Answer: Yes, You need a specialized server, Apache does not come with websockets.
OR
The alternative, check out www.achex.ca.

简短回答是的,您需要一个专门的服务器,Apache 没有提供 websockets。

另一种选择,请查看www.achex.ca

回答by Sid

In such a situation the role of server comes when :

在这种情况下,服务器的角色出现在:

In HTML 5,WebSocket like a fone(2-way comm.) not walky-talky. http protocol upgraded to websocket protocol.(wss:// from ws://)SERVER should be able to open duplex channel and hence AGREE with duplex communication.

在 HTML 5 中,WebSocket 就像一个 fone(2-way comm.) 而不是对讲机。http 协议升级为 websocket 协议。(wss:// from ws://)SERVER 应该能够打开双工通道,因此同意双工通信。

Please go through this link : http://www.html5rocks.com/en/tutorials/websockets/basics/

请通过此链接:http: //www.html5rocks.com/en/tutorials/websockets/basics/

If using php please look at RATCHET.

如果使用 php,请查看 RATCHET。

Thanks.

谢谢。

回答by LeeGee

The Perl Mojolicious server supports web sockets, and implementations can be only a few lines long.

Perl Mojolicious 服务器支持 Web 套接字,并且实现可以只有几行长。

Node.js has several WebSocket libraries but details of the latest, greatest, most supportive of the latest spec vary, so choose carefully.

Node.js 有几个 WebSocket 库,但最新、最伟大、最支持最新规范的细节各不相同,因此请谨慎选择。

Apache Active MQ is also worth a look, along with the stomp protocol it implements.

Apache Active MQ 以及它实现的 stomp 协议也值得一看。