Wallogit.com
2017 © Pedro Peláez
Fork from : https://github.com/psinetron/PHP_SocketIO_Client, (*1)
install, (*2)
php composer require touskar/php-socket-io-event-emitter
Php, (*3)
require_once '../SocketIO.php'; $client = new SocketIO('localhost', 9001); //connection handshake query( for auth - optional) $client->setQueryParams([ 'token' => 'edihsudshuz', 'id' => '8780', 'cid' => '344', 'cmp' => 2339 ]); $success = $client->emit('eventFromPhp', [ 'name' => 'Goku', 'age' => '23', 'address' => 'Sudbury, On, Canada' ]); if(!$success) { var_dump($client->getErrors()); } else{ var_dump("Success"); }
Node Js, (*4)
var app = require('http').createServer(handler) var io = require('socket.io')(app); var fs = require('fs'); app.listen(9001); function handler (req, res) { res.writeHead(200); res.end('Hello Word'); } io.on('connection', function (socket) { console.log("New Connection with transport", socket.conn.transport.name); console.log('With handshake', socket.handshake); console.log('With query', socket.handshake.query); socket.on('eventFromPhp', function (data) { console.log('Data from Php', data, JSON.parse(data)); }); });
2 - API, (*5)
.setMaxRetry(n), (*6)
$client->setMaxRetry(10);//default 5
.setRetryInterval(interval), (*7)
$client->setRetryInterval(100);// 100 ms, default 200
.setProtocole(protocol), (*8)
$client->setProtocole(SocketIO::NO_SECURE_PROTOCOLE); $client->setProtocole(SocketIO::TLS_PROTOCOLE); $client->setProtocole(SocketIO::SSL_PROTOCOLE);
.setPort(port), (*9)
$client->setPort(80);
.setPath(path), (*10)
$client->setPath('/socket.io/EIO=3');
.setHost(host), (*11)
$client->setPath('localhost');