SocketIO blocks server












0















I have a simple app that uses express to serve a static page which creates a socketio connection. The problem is the server stops responding after a minute or two. This is the code:



server.js



const path = require('path');
const http = require('http');
const express = require('express');
const socketIO = require('socket.io');
const publicPath = path.join(__dirname, './public');

const port = 3000;

let app = express();
let server = http.createServer(app);
var io = socketIO(server);

app.get(`/`, (req, res) => {
res.sendFile(publicPath + '/index.html');
});

server.listen(port, () => {
console.log('listening...');
})

io.on('connection', (socket) => {
socket.on('test', (data) => {
console.log(data);
});
});


index.html



<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>

<body class="centered">
<center><h1>This is a test</h1></center>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.on('connect', () => {
socket.emit('test', 'this is some data');
});
</script>

</body>

</html>


Package.json



{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"socket.io": "^2.1.1"
}
}


Of course there are no errors on server or client. If i remove the line var socket = io() the app runs smoothly.










share|improve this question

























  • you have absolutely no socket.io handling in the server, neither in the frontend, what are your expectation ? you should create some channels and put/read data from/in it, then we can see if the server is really not responding or not.

    – Marwen Trabelsi
    Nov 27 '18 at 10:17











  • @MarwenTrabelsi I added a simple logging on connection on both sides, The logging works fine for a minute or so, and then the server just stops responding.

    – Sagi Rika
    Nov 27 '18 at 10:23











  • you are just connecting the client to the server, there is no real input/output. can you add some events and emit some other ? just to make a real working app, the current code will hangs doing nothing.

    – Marwen Trabelsi
    Nov 27 '18 at 10:25











  • @MarwenTrabelsi Added a custom 'data' event. The server is responding to it, printing the data as expected. As usual, about 1 minute after I connect the server gets stuck.

    – Sagi Rika
    Nov 27 '18 at 10:30






  • 1





    so the problem is not about the code or at least not anything we could know, this is something related to other problems on OS side.

    – Marwen Trabelsi
    Nov 27 '18 at 14:22
















0















I have a simple app that uses express to serve a static page which creates a socketio connection. The problem is the server stops responding after a minute or two. This is the code:



server.js



const path = require('path');
const http = require('http');
const express = require('express');
const socketIO = require('socket.io');
const publicPath = path.join(__dirname, './public');

const port = 3000;

let app = express();
let server = http.createServer(app);
var io = socketIO(server);

app.get(`/`, (req, res) => {
res.sendFile(publicPath + '/index.html');
});

server.listen(port, () => {
console.log('listening...');
})

io.on('connection', (socket) => {
socket.on('test', (data) => {
console.log(data);
});
});


index.html



<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>

<body class="centered">
<center><h1>This is a test</h1></center>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.on('connect', () => {
socket.emit('test', 'this is some data');
});
</script>

</body>

</html>


Package.json



{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"socket.io": "^2.1.1"
}
}


Of course there are no errors on server or client. If i remove the line var socket = io() the app runs smoothly.










share|improve this question

























  • you have absolutely no socket.io handling in the server, neither in the frontend, what are your expectation ? you should create some channels and put/read data from/in it, then we can see if the server is really not responding or not.

    – Marwen Trabelsi
    Nov 27 '18 at 10:17











  • @MarwenTrabelsi I added a simple logging on connection on both sides, The logging works fine for a minute or so, and then the server just stops responding.

    – Sagi Rika
    Nov 27 '18 at 10:23











  • you are just connecting the client to the server, there is no real input/output. can you add some events and emit some other ? just to make a real working app, the current code will hangs doing nothing.

    – Marwen Trabelsi
    Nov 27 '18 at 10:25











  • @MarwenTrabelsi Added a custom 'data' event. The server is responding to it, printing the data as expected. As usual, about 1 minute after I connect the server gets stuck.

    – Sagi Rika
    Nov 27 '18 at 10:30






  • 1





    so the problem is not about the code or at least not anything we could know, this is something related to other problems on OS side.

    – Marwen Trabelsi
    Nov 27 '18 at 14:22














0












0








0








I have a simple app that uses express to serve a static page which creates a socketio connection. The problem is the server stops responding after a minute or two. This is the code:



server.js



const path = require('path');
const http = require('http');
const express = require('express');
const socketIO = require('socket.io');
const publicPath = path.join(__dirname, './public');

const port = 3000;

let app = express();
let server = http.createServer(app);
var io = socketIO(server);

app.get(`/`, (req, res) => {
res.sendFile(publicPath + '/index.html');
});

server.listen(port, () => {
console.log('listening...');
})

io.on('connection', (socket) => {
socket.on('test', (data) => {
console.log(data);
});
});


index.html



<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>

<body class="centered">
<center><h1>This is a test</h1></center>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.on('connect', () => {
socket.emit('test', 'this is some data');
});
</script>

</body>

</html>


Package.json



{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"socket.io": "^2.1.1"
}
}


Of course there are no errors on server or client. If i remove the line var socket = io() the app runs smoothly.










share|improve this question
















I have a simple app that uses express to serve a static page which creates a socketio connection. The problem is the server stops responding after a minute or two. This is the code:



server.js



const path = require('path');
const http = require('http');
const express = require('express');
const socketIO = require('socket.io');
const publicPath = path.join(__dirname, './public');

const port = 3000;

let app = express();
let server = http.createServer(app);
var io = socketIO(server);

app.get(`/`, (req, res) => {
res.sendFile(publicPath + '/index.html');
});

server.listen(port, () => {
console.log('listening...');
})

io.on('connection', (socket) => {
socket.on('test', (data) => {
console.log(data);
});
});


index.html



<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>

<body class="centered">
<center><h1>This is a test</h1></center>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.on('connect', () => {
socket.emit('test', 'this is some data');
});
</script>

</body>

</html>


Package.json



{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"socket.io": "^2.1.1"
}
}


Of course there are no errors on server or client. If i remove the line var socket = io() the app runs smoothly.







express socket.io






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 10:50







Sagi Rika

















asked Nov 27 '18 at 8:56









Sagi RikaSagi Rika

7311




7311













  • you have absolutely no socket.io handling in the server, neither in the frontend, what are your expectation ? you should create some channels and put/read data from/in it, then we can see if the server is really not responding or not.

    – Marwen Trabelsi
    Nov 27 '18 at 10:17











  • @MarwenTrabelsi I added a simple logging on connection on both sides, The logging works fine for a minute or so, and then the server just stops responding.

    – Sagi Rika
    Nov 27 '18 at 10:23











  • you are just connecting the client to the server, there is no real input/output. can you add some events and emit some other ? just to make a real working app, the current code will hangs doing nothing.

    – Marwen Trabelsi
    Nov 27 '18 at 10:25











  • @MarwenTrabelsi Added a custom 'data' event. The server is responding to it, printing the data as expected. As usual, about 1 minute after I connect the server gets stuck.

    – Sagi Rika
    Nov 27 '18 at 10:30






  • 1





    so the problem is not about the code or at least not anything we could know, this is something related to other problems on OS side.

    – Marwen Trabelsi
    Nov 27 '18 at 14:22



















  • you have absolutely no socket.io handling in the server, neither in the frontend, what are your expectation ? you should create some channels and put/read data from/in it, then we can see if the server is really not responding or not.

    – Marwen Trabelsi
    Nov 27 '18 at 10:17











  • @MarwenTrabelsi I added a simple logging on connection on both sides, The logging works fine for a minute or so, and then the server just stops responding.

    – Sagi Rika
    Nov 27 '18 at 10:23











  • you are just connecting the client to the server, there is no real input/output. can you add some events and emit some other ? just to make a real working app, the current code will hangs doing nothing.

    – Marwen Trabelsi
    Nov 27 '18 at 10:25











  • @MarwenTrabelsi Added a custom 'data' event. The server is responding to it, printing the data as expected. As usual, about 1 minute after I connect the server gets stuck.

    – Sagi Rika
    Nov 27 '18 at 10:30






  • 1





    so the problem is not about the code or at least not anything we could know, this is something related to other problems on OS side.

    – Marwen Trabelsi
    Nov 27 '18 at 14:22

















you have absolutely no socket.io handling in the server, neither in the frontend, what are your expectation ? you should create some channels and put/read data from/in it, then we can see if the server is really not responding or not.

– Marwen Trabelsi
Nov 27 '18 at 10:17





you have absolutely no socket.io handling in the server, neither in the frontend, what are your expectation ? you should create some channels and put/read data from/in it, then we can see if the server is really not responding or not.

– Marwen Trabelsi
Nov 27 '18 at 10:17













@MarwenTrabelsi I added a simple logging on connection on both sides, The logging works fine for a minute or so, and then the server just stops responding.

– Sagi Rika
Nov 27 '18 at 10:23





@MarwenTrabelsi I added a simple logging on connection on both sides, The logging works fine for a minute or so, and then the server just stops responding.

– Sagi Rika
Nov 27 '18 at 10:23













you are just connecting the client to the server, there is no real input/output. can you add some events and emit some other ? just to make a real working app, the current code will hangs doing nothing.

– Marwen Trabelsi
Nov 27 '18 at 10:25





you are just connecting the client to the server, there is no real input/output. can you add some events and emit some other ? just to make a real working app, the current code will hangs doing nothing.

– Marwen Trabelsi
Nov 27 '18 at 10:25













@MarwenTrabelsi Added a custom 'data' event. The server is responding to it, printing the data as expected. As usual, about 1 minute after I connect the server gets stuck.

– Sagi Rika
Nov 27 '18 at 10:30





@MarwenTrabelsi Added a custom 'data' event. The server is responding to it, printing the data as expected. As usual, about 1 minute after I connect the server gets stuck.

– Sagi Rika
Nov 27 '18 at 10:30




1




1





so the problem is not about the code or at least not anything we could know, this is something related to other problems on OS side.

– Marwen Trabelsi
Nov 27 '18 at 14:22





so the problem is not about the code or at least not anything we could know, this is something related to other problems on OS side.

– Marwen Trabelsi
Nov 27 '18 at 14:22












0






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',
autoActivateHeartbeat: false,
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%2f53495897%2fsocketio-blocks-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53495897%2fsocketio-blocks-server%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

Lallio

Unable to find Lightning Node

Futebolista