Skip to content

Instantly share code, notes, and snippets.

@Taluu
Last active August 29, 2015 14:06
Show Gist options
  • Save Taluu/21c30eedabc151d08fc0 to your computer and use it in GitHub Desktop.
Save Taluu/21c30eedabc151d08fc0 to your computer and use it in GitHub Desktop.
elephant debug
info - socket.io started
debug - client authorized
info - handshake authorized dalE823IiAof2aYIc5Vj
debug - setting request GET /socket.io/1/websocket/dalE823IiAof2aYIc5Vj/?
debug - set heartbeat interval for client dalE823IiAof2aYIc5Vj
debug - client authorized for
debug - websocket writing 1::
user connected
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
here we are in action event and data is: {"foo":"bar"}
info - transport end (socket end)
debug - set close timeout for client dalE823IiAof2aYIc5Vj
debug - cleared close timeout for client dalE823IiAof2aYIc5Vj
debug - cleared heartbeat interval for client dalE823IiAof2aYIc5Vj
Received 10 messages
debug - discarding transport
-----
debug - client authorized
info - handshake authorized IW8eqASmeX1MK3WJc5Vk
debug - setting request GET /socket.io/1/websocket/IW8eqASmeX1MK3WJc5Vk/?
debug - set heartbeat interval for client IW8eqASmeX1MK3WJc5Vk
debug - client authorized for
debug - websocket writing 1::
user connected
here we are in action event and data is: {"foo":"bar"}
debug - set close timeout for client IW8eqASmeX1MK3WJc5Vk
info - socket error Error: read ECONNRESET
at errnoException (net.js:904:11)
at TCP.onread (net.js:558:19)
debug - client authorized
info - handshake authorized AJpRRtYpgtGLYw41bxa6
debug - setting request GET /socket.io/1/websocket/AJpRRtYpgtGLYw41bxa6
debug - set heartbeat interval for client AJpRRtYpgtGLYw41bxa6
debug - client authorized for
debug - websocket writing 1::
user connected
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
here we are in action event and data is: foo
debug - got disconnection packet
info - transport end by forced client disconnection
debug - websocket writing 0::
info - transport end (booted)
debug - set close timeout for client AJpRRtYpgtGLYw41bxa6
debug - cleared close timeout for client AJpRRtYpgtGLYw41bxa6
debug - cleared heartbeat interval for client AJpRRtYpgtGLYw41bxa6
Received 10 messages
debug - discarding transport
<?php
/**
* This file is part of the Elephant.io package
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*
* @copyright Wisembly
* @license http://www.opensource.org/licenses/MIT-License MIT License
*/
use ElephantIO\Client,
ElephantIO\Engine\SocketIO\Version0X;
require __DIR__ . '/../../vendor/autoload.php';
$client = new Client(new Version0X('http://localhost:8000'));
$client->initialize();
for ($i = 0; $i < 10; ++$i) {
$client->emit('action', ['foo' => 'bar']);
}
$client->close();
<?php
require( __DIR__ . '/../vendor/autoload.php');
use ElephantIO\Client as ElephantIOClient;
$elephant = new ElephantIOClient('http://localhost:8000', 'socket.io', 1, false, true, true);
$elephant->init();
for ($i = 0; $i < 10; ++$i) {
$elephant->emit('action', 'foo');
}
$elephant->close();
var io = require('socket.io').listen(8000);
io.sockets.on('connection', function (socket) {
console.log('user connected');
var nb = 0;
socket.on('action', function (data) {
++nb;
console.log('here we are in action event and data is: ' + JSON.stringify(data));
});
socket.on('disconnect', function () {
console.log('Received ' + nb + ' messages');
});
});
diff --git a/example/emitter/client.php b/example/emitter/client.php
index 0b1cf24..d3e471f 100644
--- a/example/emitter/client.php
+++ b/example/emitter/client.php
@@ -17,5 +17,9 @@ require __DIR__ . '/../../vendor/autoload.php';
$client = new Client(new Version1X('http://localhost:1337'));
$client->initialize();
-$client->emit('broadcast', ['foo' => 'bar']);
-$client->close();
\ No newline at end of file
+
+for ($i = 0; $i < 10; ++$i) {
+ $client->emit('broadcast', ['foo' => 'bar']);
+}
+
+$client->close();
diff --git a/example/emitter/server.js b/example/emitter/server.js
index 249030b..7e37fb9 100644
--- a/example/emitter/server.js
+++ b/example/emitter/server.js
@@ -9,13 +9,17 @@ logger.add(logger.transports.Console, { colorize: true, timestamp: true });
logger.info('SocketIO > listening on port ' + port);
io.on('connection', function (socket){
+ var nb = 0;
+
logger.info('SocketIO > Connected socket ' + socket.id);
socket.on('broadcast', function (message) {
+ ++nb;
logger.info('ElephantIO broadcast > ' + JSON.stringify(message));
});
socket.on('disconnect', function () {
+ logger.info('SocketIO : Received ' + nb + ' messages');
logger.info('SocketIO > Disconnected socket ' + socket.id);
});
});
diff --git a/src/Engine/SocketIO/Version1X.php b/src/Engine/SocketIO/Version1X.php
index 778271c..c0f4cf3 100644
--- a/src/Engine/SocketIO/Version1X.php
+++ b/src/Engine/SocketIO/Version1X.php
@@ -81,7 +81,7 @@ class Version1X extends AbstractSocketIO
/** {@inheritDoc} */
public function emit($event, array $args)
{
- $this->write(EngineInterface::MESSAGE, static::EVENT . json_encode([$event, $args]));
+ return $this->write(EngineInterface::MESSAGE, static::EVENT . json_encode([$event, $args]));
}
/** {@inheritDoc} */
@@ -96,7 +96,9 @@ class Version1X extends AbstractSocketIO
}
$payload = new Encoder($code . $message, Encoder::OPCODE_TEXT, true);
- return fwrite($this->stream, (string) $payload);
+ $bytes = fwrite($this->stream, (string) $payload);
+
+ usleep(10000);
}
/** {@inheritDoc} */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment