Websocket server - gd-99/symbiogd GitHub Wiki
A PHP Websocket server is included in Symbiose, with several endpoints:
- An API endpoint to send almost all data through Websockets
- A [PeerJS server](PeerJS server)
- A normal HTTP server: you can browse directly to your server's URL in order to use Symbiose. Thus, when using the Websocket server, you don't need an additional port with another web server for normal HTTP requests (e.g. Apache or Nginx).
Starting the server
You can start the Websocket server either automatically or manually.
Start the server automatically
Requirements: an Unix-like OS, with nohup
and kill
available.
Go to System preferences > WebSocket server > Configuration. Here you can change some settings such as the server port, and you can start the server.
By default, the server will start on port 9000.
Server logs are available in /var/log/websocket-server.log
.
Start the server manually
Sometimes, it is more convenient to start the server manually, just like a Node.js server for instance. You can do so by running this command:
php sbin/server.php
You can now open http://localhost:9000
to use Symbiose.
You can override the server port when launching the server : php sbin/server.php -p 8080
.
Configuration
All configuration is stored in /etc/websocket-server.json
. Available options:
enabled
: set to true to enable the websocket serverautoStart
: set to true to automatically start the websocket server if it is downhostname
: allowed origin. Set to*
to allow any origin.port
: the websocket server port. Defaults to9000
. Set tonull
to detect the port from the URL.protocol
: the server protocol, can bews
orwss
for a secure connection. Set tonull
to detect the protocol from the URL.
SSL support
SSL is not supported for now. Nevertheless, you can use a reverse proxy to enable SSL. Here is an example with Nginx: https://stackoverflow.com/questions/22493646/ratchet-nginx-ssl-secure-websocket
It's also possible with Apache: https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
Node.js reverse proxy
Uses http-proxy
.
var fs = require('fs');
var httpProxy = require('http-proxy');
httpProxy.createServer({
target: {
host: 'localhost',
port: 9000
},
ssl: {
key: fs.readFileSync('certificate.pem', 'utf8'),
cert: fs.readFileSync('certificate.pem', 'utf8')
},
ws: true
}).listen(3000);
console.log('Proxy listening on port 3000');
Generating certificates:
openssl req -newkey rsa:2048 -days 730 -x509 -nodes -keyout certificate.key -out certificate.cert
cat certificate.cert certificate.key > certificate.pem
Installing http-proxy
:
npm install http-proxy