【发布时间】:2016-06-16 21:12:28
【问题描述】:
我正在尝试使用 PHP WebSocket 服务器来运行聊天应用程序。 它在本地主机上对我有用,但是当我将其上传到具有 DNS 的域时,javascript 无法连接到服务器。
server.php
<?php
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/So/Chat.php';
use So\Chat;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
//What to write here?
$server = IoServer::factory(new HttpServer(new WsServer(new Chat)) 8080,'192.168.1.12');
$server->run();
?>
connection.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();
}
【问题讨论】:
-
您能否发布 PHP 代码以便我们更好地理解您的问题?
-
你的服务器IP正确吗?
-
是的,你认为问题出在 ip 上?
-
我不熟悉该库,但我愿意猜测
'5.29.101.176:80'作为第二个参数并不正确,因为您无法真正打开远程服务器上的套接字使用一个本地运行的脚本(或者你可以吗?) -
我不知道,它在本地主机上对我有用,我更正了上面的代码。
标签: javascript php websocket server ip