2016-03-03 23 views
0

我想要做的是運行聊天應用程序的PHP WebSocket服務器。 它在localhost上爲我工作,但是當我使用DNS將它上傳到域時,javascript不連接到服務器。從私人計算機發布php websocket服務器

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(); 
    } 
+0

你能後的PHP代碼,使我們能夠更好地理解你的問題? –

+0

服務器的IP是否正確? – apokryfos

+0

是的,你認爲問題是IP? – Adi1231234

回答

0
$server = IoServer::factory(new HttpServer(new WsServer(new Chat)),80,'127.0.0.1'); 
    $server->run(); 

嘗試這種在服務器端

+0

好的,在js中要改變什麼? – Adi1231234

+0

沒有在JS你需要把你的Web服務器公共IP – Vigikaran

+0

它說:WebSocket連接到'WS://5.29.101.176/'失敗:在WebSocket握手期間出錯:意外的響應代碼:200 – Adi1231234