Multiple Websockets

前端 未结 3 1153
误落风尘
误落风尘 2020-12-15 06:12

I\'m trying to use two websockets on one page. This is my code:

var pageViewWs = new WebSocket(\"ws://localhost:9002/pageView\");
var sessionWs = new WebSoc         


        
3条回答
  •  无人及你
    2020-12-15 06:41

    I faced the same problem to run multiple services through the same port. So, I created a PHP library to do this.

    Why ?

    Some free plans of hosting providers don't allow you to bind to ports or allow you to bind to one port. In case of OpenShift Cloud Server, you can only bind to port 8080. So, running multiple WebSocket services is not possible. In this case, Francium DiffSocket is useful.

    You can run different services on the same port using a PHP library called Francium DiffSocket.

    After setting up Francium DiffSocket, you can do this for using different services :

    var chatWS = new WebSocket("ws://ws.example.com:8000/?service=chat");
    var gameWS = new WebSocket("ws://ws.example.com:8000/?service=game");
    

    An example are these services which are running through a single port :

    • Finding Value Of Pi
    • Advanced Live Group Chat With PHP, jQuery & WebSocket
    • Live Group Chat With PHP, jQuery & WebSocket

提交回复
热议问题