设置Apache的一个WebSocket的? [英] Setting up a websocket on Apache?

查看:234
本文介绍了设置Apache的一个WebSocket的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在做的WebSockets一些研究,我有几个问题,我似乎无法找到一个明确的答案:

So I'm doing some research on websockets, and I have a few questions I can't seem to find a definitive answer for:


  • 我如何设置我的Linux服务器上的Web接口?是否有一个Apache模块?我会有无的使用第三方PHP code或相似?

  • How can I set up a web socket on my Linux server? Is there an Apache module? Would I have to use 3rd-party PHP code or similar?

是否有任何种类的弊端在问题1中描述的方法,我应该比浏览器的兼容性知道其他?

Are there any kinds of drawbacks to the method described in question 1 that I should be aware of other than browser compatibility?

我怎么能升级我的WebSocket安装到一个安全的WebSocket安装(WS://到WSS://)?这会作出更容易或更困难,如果SSL已经设立了我的Apache服务器?

How could I "upgrade" my websocket installation to a secure websocket installation (ws:// to wss://)? Would this be made easier or more difficult if SSL was already set up on my Apache server?

有没有我可以用它来连接到比其他的JavaScript我的网络插座?

Is there any language I could use to connect to my web socket other than JavaScript?

什么是网络套接字的默认请求方法?

What is the default request method for a web socket?

推荐答案

我不能回答所有的问题,但我会尽我所能。

I can't answer all questions, but I will do my best.

正如你已经知道,WS是构造消息只有一个持久的全双工TCP连接,其中初始握手是类似于HTTP。你需要一些的监听传入WS请求的服务器,并能结合处理他们。

As you already know, WS is only a persistent full-duplex TCP connection with framed messages where the initial handshaking is HTTP-like. You need some server that's listening for incoming WS requests and that binds a handler to them.

现在有可能与Apache HTTP服务器,和我见过一些例子,但没有官方的支持,它变得复杂。你会阿帕奇怎么办?哪里会是你的处理器?有转发传入的WS的请求到外部共享库的模块,但是这不是必要与其它大的工具使用WS工作

Now it might be possible with Apache HTTP Server, and I've seen some examples, but there's no official support and it gets complicated. What would Apache do? Where would be your handler? There's a module that forwards incoming WS requests to an external shared library, but this is not necessary with the other great tools to work with WS.

WS服务器的发展趋势现在包括:高速公路(蟒蛇)和插座。 IO (在服务器上的Node.js = JavaScript的)。后者还支持像长轮询和所有 COMET 东西等hackish的老大难连接。还有像棘轮其他鲜为人知的WS服务器框架(PHP,如果你只熟悉)。

WS server trends now include: Autobahn (Python) and Socket.IO (Node.js = JavaScript on the server). The latter also supports other hackish "persistent" connections like long polling and all the COMET stuff. There are other little known WS server frameworks like Ratchet (PHP, if you're only familiar with that).

在任何情况下,你将需要侦听端口,当然这个端口不能是相同的Apache HTTP服务器计算机(默认为80分钟)已经在运行。你可以使用像8080,但即使这个特殊的是一个受欢迎的选择,一些防火墙可能仍然阻止它,因为它不应该是Web流量。这就是为什么许多人选择443,这是的 HTTP安全的是,由于显而易见的原因,防火墙没有阻止端口。如果你没有使用SSL,您可以使用80用于HTTP和443 WS。对WS服务器不需要是安全的;我们只是使用的端口。

In any case, you will need to listen on a port, and of course that port cannot be the same as the Apache HTTP Server already running on your machine (default = 80). You could use something like 8080, but even if this particular one is a popular choice, some firewalls might still block it since it's not supposed to be Web traffic. This is why many people choose 443, which is the HTTP Secure port that, for obvious reasons, firewalls do not block. If you're not using SSL, you can use 80 for HTTP and 443 for WS. The WS server doesn't need to be secure; we're just using the port.

关于协议,如维基百科显示,它看起来像这样:

About the protocol, as Wikipedia shows, it looks like this:

客户端发送:

GET /mychat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat
Sec-WebSocket-Version: 13
Origin: http://example.com

服务器回复:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat

和保持活着的连接。如果能实现这个握手和基本框架消息(封装与描述它的小头的每个消息),那么你可以使用任何你想要的客户端语言。因为它内置的JavaScript仅在Web浏览器中使用。

and keeps the connection alive. If you can implement this handshaking and the basic message framing (encapsulating each message with a small header describing it), then you can use any client-side language you want. JavaScript is only used in Web browsers because it's built-in.

正如你所看到的,默认的请求方法是初始HTTP GET,虽然这不是真正的HTTP和这个握手之后,在失去一切共同使用HTTP。我想,不支持服务器

As you can see, the default "request method" is an initial HTTP GET, although this is not really HTTP and looses everything in common with HTTP after this handshaking. I guess servers that do not support

Upgrade: websocket
Connection: Upgrade

将与错误信息或与页面内容回复。

will reply with an error or with a page content.

这篇关于设置Apache的一个WebSocket的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆