问题描述
我有一个棘手的聊天服务器文件
I have a ratchet chat server file
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use MyAppChat\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new WsServer(
new Chat()
)
, 26666
);
$server->run();
我使用Websocket与ws
连接,并且工作正常
I using Websocket to connect with ws
and it works fine
if ("WebSocket" in window) {
var ws = new WebSocket("ws://ratchet.mydomain.org:8888");
ws.onopen = function() {
// Web Socket is connected. You can send data by send() method.
ws.send("message to send");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
};
ws.onclose = function() {
// websocket is closed.
};
} else {
// the browser doesn't support WebSocket.
}
我想要安全的连接,所以我尝试使用SSL进行连接,但是不起作用.
I want secure connection, so I try to connect with SSL but is not work.
if ("WebSocket" in window) {
var ws = new WebSocket("wss://ratchet.mydomain.org:8888");
ws.onopen = function() {
// Web Socket is connected. You can send data by send() method.
ws.send("message to send");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
};
ws.onclose = function() {
// websocket is closed.
};
} else {
// the browser doesn't support WebSocket.
}
我的问题是如何通过SSL连接连接网络套接字
有什么主意吗?
推荐答案
如果您使用的是Apache Web服务器(2.4或更高版本),请在httpd.conf文件中启用以下模块:
If you are using Apache web server (2.4 or above), enable these modules in httpd.conf file :
- mod_proxy.so
- mod_proxy_wstunnel.so
将此设置添加到您的httpd.conf文件
Add this setting to your httpd.conf file
ProxyPass /wss2/ ws://ratchet.mydomain.org:8888/
要建立WSS连接时,请在JavaSscript调用中使用以下URL:
Use this URL in your JavaSscript call when you want a WSS connection:
var ws = new WebSocket("wss://ratchet.mydomain.org/wss2/NNN");
在应用设置(telnet主机名端口)之前,重新启动Apache Web服务器并确保您的Ratchet worker(Web套接字连接)已打开.
Restart Apache web server and make sure that your Ratchet worker (web socket connection) is open before applying the settings (telnet hostname port).
这篇关于PHP棘轮websocket SSL连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!