我有一个棘手的聊天服务器文件
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效果很好
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. }
我的问题是 如何将Websocket与SSL连接连接
任何的想法?
如果您使用的是Apache Web服务器(2.4或更高版本),请在httpd.conf文件中启用以下模块:
将此设置添加到您的httpd.conf文件
ProxyPass /wss2/ ws://ratchet.mydomain.org:8888/
需要WSS连接时,请在JavaSscript调用中使用以下URL:
var ws = new WebSocket("wss://ratchet.mydomain.org/wss2/NNN");
重新启动Apache Web服务器,并在应用设置(telnet主机名端口)之前,确保您的Ratchet worker(Web套接字连接)已打开。