Answer the question
In order to leave comments, you need to log in
How to connect socket.io, express, session?
There are several static html files that need to communicate with the nodejs server in real time. In particular, the server must receive the session id of the users. I found several ready-made solutions, but with more complex functionality (using databases, template engines, debuggers, etc.), which complicates the ability to deal with them. The code of the server part is of interest: the return of statics, the exchange of data between the client and the server, interaction with sessions.
Answer the question
In order to leave comments, you need to log in
app.js
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.sockets.on('connection', function(client) {
console.log("Client connected...");
client.on('question', function(question) {
if(!client.question_asked) {
client.question_asked = true;
client.broadcast.emit('question', question);
}
});
});
server.listen(8080);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question