Express-session and express-socket.io-session not working in angular2 / typescript environment
Date : March 29 2020, 07:55 AM
may help you . You can have socket.io run with Express easily. By simply invoking socket.io’s listen method and passing it the Express Session as a Middleware(Assuming you are storing all your sessions in FileSystem and not in Redis). I have made a replication of your Code which goes as follows: var e_session = require("express-session");
var io_session = require("socket.io")(server);
//Storing sessions in file system
var sessionFileStore = require('session-file-store')(Session);
//Express-Sessions as middleware
var e_sessionMiddleware = e_session({
store: new sessionFileStore({ path: './project-x/sessions' }),
secret: 'pass', resave: true,
saveUninitialized: true
});
//Use of Express-Session as Middleware
io_session.use(function(socket, next) {
e_sessionMiddleware(socket.handshake, {}, next);
});
//Socket Io session and express sessions are now same
io_session.on("connection", function(socket) {
socket.emit(socket.handshake.session);
});
|
socket.io server not listening to connection event (express server)
Date : March 29 2020, 07:55 AM
I wish this help you To see a socket.io connection on the server, you need client-side code in your web page that creates the socket.io connection. That would typically look like this: <script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
// do more things with the connection here
</script>
|
Sharing session between socket.io and express not working on remote server
Date : March 29 2020, 07:55 AM
To fix this issue Making my comment into an answer since it appears to have solved your issue: You need to make sure the address in the URL bar of the browser is EXACTLY the same host/port like http://ip.ad.dr.ess:80? If not, then socket.io and the web page won't share cookies and thus you would miss the session cookie.
|
is there any way to run socket.io with only express server
Date : March 29 2020, 07:55 AM
I hope this helps . No. Starting with 3.0, express applications have become request handler functions that you pass to http or http Server instances. You need to pass the Server to socket.io, and not the express application function. Also make sure to call .listen on the server, not the app. var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server); //listen server not app
io.on('connection', function(){ /* … */ });
server.listen(3000);
|
How to make mutiple socket writes with one active socket connection to an express web server?
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to do multiple write requests with one active socket connection to an express server running on localhost. int total, bytes, received = 0;
memset(response, 0, RESPONSE_SIZE);
total = RESPONSE_SIZE - 1;
do {
bytes = read(*socket_ref, response + received, total - received);
if (bytes < 0) {
perror("ERROR reading response from socket yo");
exit(EXIT_FAILURE);
}
if (bytes == 0) break;
received += bytes;
} while (received < total);
|