Comments (21)
Is there any error ?
On Friday, August 29, 2014, ToToSe [email protected] wrote:
Hello,
I use elephant.io with socket.io for my tchat to send new message,
but when i'm sending messages they do not pass all.Here it is my php code for sending sockets :
$socket = new Client(new Version1X('http://ourIpServer:8080'));
$socket->initialize();
$socket->emit('_ServerNewMsg', ['username' => $username, 'message' =>
$message, 'token' => 'xxx']);
$socket->close();Thx for the help (and sorry for my bad english ! :) )
—
Reply to this email directly or view it on GitHub
#68.
from elephant.io.
No we've got 0 error.
(I use try)
try
{
$socket = new Client(new Version1X('http://127.0.0.1:8080'));
$socket->initialize();
$socket->emit('_ServerNewMsg', ['username' => $username, 'message' => $message, 'token' => 'xxx']);
$socket->close();
}
catch(Exception $e) {
exit($e);
}
echo 'good!';
it allways show good
EDIT : We used winston to try to find where the problem came from and when we send a socket, when it work it show this on nodeJs :
2014-08-29T16:55:34.958Z - info: SocketIO > Connected socket Zi6NAyAZGeO0aiLrAAAQ
{ message : 'test' }
2014-08-29T16:55:34.960Z - info: SocketIO > Disconnected socket Zi6NAyAZGeO0aiLrAAAQ
But when the socket doen't send it show this :
2014-08-29T16:55:34.958Z - info: SocketIO > Connected socket Zi6NAyAZGeO0aiLrAAAQ
2014-08-29T16:55:34.960Z - info: SocketIO > Disconnected socket Zi6NAyAZGeO0aiLrAAAQ
As you can see, Elephant.io is able to connect to our server, but the socket doens't emit :/
from elephant.io.
@ToToSe I'm so sorry... I don't understand to your think.
Did you send ['username' => $username, 'message' => $message, 'token' => 'xxx']
from Client::emit()
function on elephant.io?
Did you show to debug message of emit
data like before is { message : 'test' }
?
from elephant.io.
Maybe the version about socket.io of nodejs would be 0.X.
Can you test for code like next?
$socket = new Client(new Version0X('http://ourIpServer:8080'));
$socket->initialize();
$socket->emit('_ServerNewMsg', ['username' => $username,
'message' => $message,
'token' => 'xxx']);
$socket->close();
from elephant.io.
Still doens't work :/, and yes i send ['username' => $username, 'message' => $message, 'token' => 'xxx'] with Client::emit() function on elephant.io
from elephant.io.
@ToToSe Can you show to me the source about socket.io of nodejs?
If the version of socket.io was used 1.0.0 more, execute of console command like next.
anonymous@localhost your socket.io path
$ DEBUG=socket.io* node your-server
and
Can you show to output string(debug messages) to me?
from elephant.io.
Could you just paste here your node script that receives this event (just the socket.on(...)
, even if it is only this call that I'm interested in.
The thing is, I also had this problem yesterday, but after a while, it seemed to work by itself when I did nothing, so I'm not sure if it is not a problem from socket.io or indeed one from Elephant.
Marking this ticket as "support" until a bug is found, if there's one.
from elephant.io.
Me too, some time does not send properly.
There is no error.
From the log it is just connected and then disconnected.
$client = new \ElephantIO\Client(new \ElephantIO\Engine\SocketIO\Version1X('http://localhost:1337'));
$client->initialize();
$emit_result = $client->emit('broadcast', array('sayhi' => 'Hello Hi :: ' .date('Y-m-d H:i:s')));
$client->close();
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var port = 1337;
var fs = require('fs');
var logger = require('winston');
function handler (req, res) {
fs.readFile(__dirname + '/index.html', function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
// Logger config
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, { colorize: true, timestamp: true });
logger.info('SocketIO > listening on port ' + port);
// listen to what port?
app.listen(port, function(){
//console.log('listening on *:'+port);
logger.info('Listening on *:'+port);
});
/*app.get('/', function(req, res){
res.sendfile('index.html');
});*/ // no need, use handler instead.
io.on('connection', function(socket){
//console.log('a user connected : '+socket.id);
logger.info('SocketIO > Connected socket '+socket.id);
socket.on('broadcast', function (message) {
//console.log('ElephantIO broadcast > ' + JSON.stringify(message));
logger.info('ElephantIO broadcast > ' + JSON.stringify(message));
socket.broadcast.emit('broadcast', message);
});
socket.on('disconnect', function () {
//console.log('SocketIO > Disconnected socket ' + socket.id);
logger.info('SocketIO > Disconnected socket ' + socket.id);
});
});
Test by reload php page every second. Reload 10 times but data send about 6-9 times.
I'm not sure is this elephant.io problem or socket.io problem.
from elephant.io.
I was catched exception about this problem. This problem of @ve3 will occur to source like next.
$client = new Client(new Version1X('http://localhost:1337')); $client->initialize(); for ($i = 0; $i < 10; $i++) { $emit_result = $client->emit('broadcast', ['sayhi' => 'Hello Hi :: ' .date('Y-m-d H:i:s'), 'index' => $i]); } $client->close();When the code of before is testing, Send to 10 times but data send about 6-9 times.
@Taluu I think that this problem should check about version 1.x and 0.x of elephant.io.The Results of all test cases was executed about code to same.
from elephant.io.
So i'll test it with 2.0 and see if this is a problem of either the payload or something else
from elephant.io.
It seems I can't make the legacy example work (an offset not set on the transport), but I think I could reproduce this, but I have no clue as to why it doesn't send all the messages.
Sometimes I have all the messages sent, sometimes I don't (for 10 messages sent, I am receiving between 2 to 7 messages) ; even adding a small sleep time via a usleep
doesn't seem to do the trick... I'm gonna check if the messages are indeed sent (it the call to fwrite
is done).
from elephant.io.
OK, back from some more tests ;
It would seem that it indeed comes from a problem within Elephant 3, as the legacy seems to work pretty well. I also tried the Version0x
and Version1x
with elephant 3, which revealed that both of those were having problems.
I added in the write
method another sleep time usleep(10000)
(10 milliseconds), which seems to make everything work. I think I should now ponder which time is the best, so that it doesn't cause any other error (would it be due to the socket being too overloaded between its message, hence making it miss some of those ?), but not something too far as it would kind of ruin the interest of using socket.io.
Here is the gist that show how I debugged everything : https://gist.github.com/Taluu/21c30eedabc151d08fc0
@kbu1564 & @ve3 : could you try to add, just at the end of the write
method (after the call to fwrite
) the said usleep(10000);
, and see if the results are acceptable ? Thanks.
from elephant.io.
Yes, it works very well.
from elephant.io.
I recall we experienced this behavior in 2.x version, and we had to ensure transport went well by adding usleep
too. We made many tests and found that 100ms was the "smallest safest" acceptable value. We should stick to that again by default, with maybe a way to customize it by config.
from elephant.io.
On my tests, it seems that 4ms is enough, but meh, I'll stick to the 100ms then (one never knows).
I'm adding a config for that while I'm at it.
from elephant.io.
Just as external point of view, it's strange to have to hack like that (sleeping a certain amount of ms). Do you know how the JS socket.io client is handling that behaviour ?
from elephant.io.
It doesn't seem so (as far as I can decode node scripts...), but I also think that such a behaviour is strange indeed.
But as I have nothing else, and this seems to work, it should work as a temporary patch until someone can gives us more insight on that.
from elephant.io.
We might avoid this hack by implementing the callback return to acknowledge the message has successfully been sent before trying to send another one. No ? cc @Taluu
from elephant.io.
It's looking like a best design fix this issue :) BTW, this may cause performance regressions... Maybe we could implement an "sending buffer" which is waiting acks of a certain number of messages, instead of just one?
from elephant.io.
I tried to check if there was a return (by reading the socket), but it doesn't seem so, or it is gibberish.. Seems to be some leftovers from the socket.
If you feel like finding a better solution, feel free to implement it ! Right now, this rudimentary patch should do the trick.
from elephant.io.
OK I marked this ticket as fixed ; as I said, if there is a better solution, feel free to open a PR.
from elephant.io.
Related Issues (20)
- SSL routines:SSL_write:protocol is shutdown HOT 7
- In Version1X.php line 194: Notice: Undefined index: upgrades HOT 8
- Set headers over SSL HOT 2
- readBytes while when fread return empty string
- Read and emit message from php HOT 1
- Path in socket connection HOT 1
- Get Session for distribute login user data?
- Slowness issue HOT 1
- oncesk/elephant.io for php7 HOT 1
- socket.io 3 HOT 9
- connect to socket io of ws://
- connection event not being called HOT 2
- An error occurred while trying to establish a connection to the server HOT 4
- Is Elephant.io can be used to connect through websocket?
- elephant.io is 100% down hard. HOT 1
- Fatao Error: ServerConnectionFailureException HOT 2
- did someone tried to use it with socket.io version 4x ? HOT 1
- suddenly can't establish connection with server HOT 4
- Using Version2X but getting a Version1X error ? HOT 4
- UnexpectedValueException "The server returned an unexpected value. Expected "HTTP/1.1 101", had "HTTP/1.1 400"" #217 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elephant.io.