2017-08-03 224 views
0

我在Symfony中使用Gos Web Socket Bundle,我嘗試在demo they give中工作。我很迷惑關於端口,因爲它的工作原理,如果端口127.0.0.1:1337但是當我運行的symfony的服務器時,它產生127.0.0.1:8000,所以我嘗試添加在這裏」Websocket在服務器中不工作127.0.0.1:8000

gos_web_socket: 
    server: 
     port: 8000  #The port the socket server will listen on 
     host: 127.0.0.1 #The host ip to bind to 
     router: 
      resources: 
       - '@AppBundle/Resources/config/pubsub/routing.yml' 

,並在JavaScript中的WebSocket

var websocket = WS.connect("ws://127.0.0.1:8000"); 

當我把它顯示在我的頁面上的時候。我總是得到不好的要求。但如果我使用WS.connect("ws://127.0.0.1:1337");它可以工作,而我從symfony運行的服務器是127.0.0.1:8000。我會很高興,如果你解釋爲什麼我需要使用1337端口的原因比8000

+0

您不必強制使用端口1337,只是在服務器中打開的端口和/或防火牆;可能8000端口沒有打開。 – Triby

回答

1

恕我直言,端口8000已被其他服務佔用。我會懷疑PHP內置服務器,因此請檢查php bin/console server:status正在監聽的服務器的端口。如果端口是8000,那麼停止它php bin/console server:stop,並在其他端口php bin/console server:start 127.0.0.1:8000上啓動,然後websocket將在8000上可用。

+0

我試試這個'php bin/console server:status 127.0.0.1:8080'。結果是'沒有Web服務器正在監聽http://127.0.0.1:8080'。所以我將websocket設置爲8080。當我運行'php app/console gos:websocket:server'的時候刷新我的頁面。我得到了錯誤的請求結果 – user3818576

+0

如果您通過瀏覽器訪問「http://127.0.0.1:port/app_dev.php/app/example」,該怎麼辦? –

+0

它顯示頁面,但我一直得到這個錯誤'WebSocket連接到'ws://127.0.0.1:8080 /'失敗:連接在收到握手響應之前關閉了' – user3818576