我有一个活动聊天服务器文件。
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
,并且它运行良好。
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进行连接,但无法正常工作。
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连接WebSocket,有什么想法吗?
var conn = new WebSocket('wss://localhost/wss2/');
ProxyPass /wss2/ ws://localhost:8080/
$server = IoServer::factory( new HttpServer( new WsServer( new Chat() ) ), 8080 );
- Joe Leonard