ExpressJS & Websocket & session sharing

I found this works for me. Not sure it’s the best way to do this though. First, initialize your express application: // whatever your express app is using here… var session = require(“express-session”); var sessionParser = session({ store: session_store, cookie: {secure: true, maxAge: null, httpOnly: true} }); app.use(sessionParser); Now, explicitly call the session middleware from … Read more

REST API with active push notifications from server to client

I would use RabbitMQ and consume events forwarding them as push notifications. This will work while the user is not actively connected to the website and enhance the engagement with each user experience that will return to the website when notified for more information see How to setup basic web push notification functionality using a … Read more

Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

CONNECTION_REFUSED is standard when the port is closed, but it could be rejected because SSL is failing authentication (one of a billion reasons). Did you configure SSL with Ratchet? (Apache is bypassed) Did you try without SSL in JavaScript? I don’t think Ratchet has built-in support for SSL. But even if it does you’ll want … Read more

What’s the best practice to renew a token for a WebSocket connection

Quite an old question I’ve asked, so I’d be happy to share our chosen practice: Once the client gets his JWT for the first time (when the application starts), a WebSocket is opened. To authenticate the channel, we send a message that we define as part of our protocol, called authMessage which contains that JWT. … Read more

Is it possible to use port 80 for both HTTP and web socket traffic?

YES, by using node.js. Express or connect for the HTTP file serving and socket.io for the WebSocket stuff. Example: var express = require(“express”); var app = express.createServer(); app.get(“https://stackoverflow.com/”, function(req, res){ res.redirect(“/index.html”); }); app.configure(function(){ app.use(express.static(__dirname + ‘/public’)); }); app.listen(80); var io = require(‘socket.io’); var socket = io.listen(app); socket.on(‘connection’, function(client){ client.on(‘message’, function(){…}); })

node.js – handling TCP socket error ECONNREFUSED

I ran the following code: var net = require(‘net’); var client = net.connect(5558, ‘localhost’, function() { console.log(“bla”); }); client.on(‘error’, function(ex) { console.log(“handled error”); console.log(ex); }); As I do not have 5558 open, the output was: $ node test.js handled error { [Error: connect ECONNREFUSED] code: ‘ECONNREFUSED’, errno: ‘ECONNREFUSED’, syscall: ‘connect’ } This proves that the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)