从私人计算机发布 PHP WebSocket 服务器



我想做的是PHP WebSocket服务器来运行聊天应用程序。它在本地主机上对我有用,但是当我将其上传到带有DNS的域时,javascript无法连接到服务器。

服务器.php

<?php   
  require __DIR__ . '/../vendor/autoload.php';
  require __DIR__ . '/So/Chat.php';
  use SoChat;
  use RatchetServerIoServer;
  use RatchetHttpHttpServer;
  use RatchetWebSocketWsServer;
                                                                    //What to write here?
  $server = IoServer::factory(new HttpServer(new WsServer(new Chat)) 8080,'192.168.1.12');
  $server->run();
?>

连接.js

    function Connection(username, chatWindowId) {
        this.username = username;
        this.chatwindow = document.getElementById(chatWindowId);
        this.open = false;
        this.socket = new WebSocket("ws://5.29.101.176:80");//And here?
        this.setupConnectionEvents();
    }
  $server = IoServer::factory(new HttpServer(new WsServer(new Chat)),80,'127.0.0.1'); 
  $server->run();

在服务器端尝试一下

相关内容

  • 没有找到相关文章

最新更新