Download the PHP package francium/diffsocket without Composer
On this page you can find all versions of the php package francium/diffsocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download francium/diffsocket
More information about francium/diffsocket
Files in francium/diffsocket
Package diffsocket
Short Description A PHP Library for serving Multiple WebSocket Services in a single server
License Apache 2.0
Informations about the package diffsocket
DiffSocket
A PHP Library for serving multiple WebSocket services through a single port.
Normally, if you want to run multiple services, you would have to run WebSocket server on different ports. With DiffSocket, you can use a single port for different services.
Installation
Why don't I use different ports for different services ?
Some hosting providers don't allow you to bind on multiple ports, especially if you're using a Free plan. An example is OpenShift.
I created DiffSocket, because my WebSocket server is hosted on OpenShift and needed a way to serve multiple WebSocket services through a single port.
Demos
These different services are provided through a single WebSocket port (ws-subins.rhcloud.com:8000) :
- Finding Value Of Pi
- Advanced Live Group Chat With PHP, jQuery & WebSocket
- Live Group Chat With PHP, jQuery & WebSocket
Usage
Server
DiffSocket uses Ratchet for the WebSocket server. You should learn Ratchet to create services.
-
Configure server :
-
To add a new service, create a class under namespace
Fr\DiffSocket\Service
SayHello.php
Then, you should register the service to DiffSocket by :
- Then, add the code to run the server
You may also add services as an array when the object is made :
Client
Just add the service name in the URL as a GET parameter. Notice the use of /
before ?
:
An example in JavaScript :
If the GET paramater service
is not passed or the value passed to it doesn't match any available services, then DiffSocket would refuse the connection and close it.