Answer the question
In order to leave comments, you need to log in
Socket.io doesn't want to emit connections right away, is this a bug?
I want to do this: when connecting, the user sends an emit with certain data.
Everything seems to be correct, BUT the first emit is simply not sent to frames empty, the second one works fine.
Is this a socket.io bug or what?
<script>
$(document).ready(function(){
var socket = io.connect('localhost:81');
socket.on('connect',function(){
console.log('Подключение к серверу успешно!');
socket.emit('test1','data1');
socket.emit('test2','data2');
});
});
</script>
Answer the question
In order to leave comments, you need to log in
Have you made sure on the server side that it does not come?
The fact is that socket.io tries several "transports" - first polling, then websocket. Since polling usually works, the first packet is transmitted through it, the subsequent ones are transmitted through the web socket, because the first one will not appear there, it was sent earlier.
You can disable transports other than the websocket with the second parameter:
var socket = io.connect('localhost:81', {transports: ['websocket'], upgrade: false});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question