Node.js, socket.io - io.emit doesn't work for a few seconds











up vote
0
down vote

favorite












I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb is emitted from the client like so: socket.emit('passBomb');



This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:



socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});


If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.



How could I go about fixing this?










share|improve this question






















  • Have you tried adding some console.log()'s to see if the logs as instant or taking a few seconds?
    – NewToJS
    3 hours ago










  • At which point does your button appear again? what triggers it? please post that code?
    – Sparlarva
    2 hours ago










  • I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
    – TheProgrammedDev
    1 hour ago










  • And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
    – TheProgrammedDev
    1 hour ago










  • It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
    – TheProgrammedDev
    1 hour ago















up vote
0
down vote

favorite












I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb is emitted from the client like so: socket.emit('passBomb');



This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:



socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});


If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.



How could I go about fixing this?










share|improve this question






















  • Have you tried adding some console.log()'s to see if the logs as instant or taking a few seconds?
    – NewToJS
    3 hours ago










  • At which point does your button appear again? what triggers it? please post that code?
    – Sparlarva
    2 hours ago










  • I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
    – TheProgrammedDev
    1 hour ago










  • And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
    – TheProgrammedDev
    1 hour ago










  • It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
    – TheProgrammedDev
    1 hour ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb is emitted from the client like so: socket.emit('passBomb');



This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:



socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});


If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.



How could I go about fixing this?










share|improve this question













I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb is emitted from the client like so: socket.emit('passBomb');



This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:



socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});


If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.



How could I go about fixing this?







javascript node.js socket.io






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









TheProgrammedDev

13




13












  • Have you tried adding some console.log()'s to see if the logs as instant or taking a few seconds?
    – NewToJS
    3 hours ago










  • At which point does your button appear again? what triggers it? please post that code?
    – Sparlarva
    2 hours ago










  • I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
    – TheProgrammedDev
    1 hour ago










  • And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
    – TheProgrammedDev
    1 hour ago










  • It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
    – TheProgrammedDev
    1 hour ago


















  • Have you tried adding some console.log()'s to see if the logs as instant or taking a few seconds?
    – NewToJS
    3 hours ago










  • At which point does your button appear again? what triggers it? please post that code?
    – Sparlarva
    2 hours ago










  • I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
    – TheProgrammedDev
    1 hour ago










  • And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
    – TheProgrammedDev
    1 hour ago










  • It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
    – TheProgrammedDev
    1 hour ago
















Have you tried adding some console.log()'s to see if the logs as instant or taking a few seconds?
– NewToJS
3 hours ago




Have you tried adding some console.log()'s to see if the logs as instant or taking a few seconds?
– NewToJS
3 hours ago












At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago




At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago












I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago




I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago












And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago




And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago












It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago




It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349378%2fnode-js-socket-io-io-emit-doesnt-work-for-a-few-seconds%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349378%2fnode-js-socket-io-io-emit-doesnt-work-for-a-few-seconds%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin