Python – Flask-SocketIO send message from thread: not always working

I managed to resolve the issue by monkeypatching several Python functions which causes Python to use the eventlet functions instead of the native ones. This way background threads work fine with eventlet. https://github.com/miguelgrinberg/Flask-SocketIO/blob/e024b7ec9db4837196d8a46ad1cb82bc1e15f1f3/example/app.py#L30-L31

Socket.IO without http server?

Socket.io, and WebSockets in general, require an http server for the initial upgrade handshake. So even if you don’t supply Socket.io with an http server it will create one for you. The issue is that the second parameter in your io.listen(3000, ‘0.0.0.0’) is ignored by Socket.io. If you need to control which network interface to … Read more

express.js 4 and sockets with express router

One option is to pass it in to req object. app.js: var express = require(‘express’); var path = require(‘path’); var logger = require(‘morgan’); var api = require(‘./routes/api’); var app = express(); var io = require(‘socket.io’).listen(app.listen(3000)); app.use(logger(‘dev’)); app.use(express.static(path.join(__dirname, ‘public’))); io.sockets.on(‘connection’, function (socket) { console.log(‘client connect’); socket.on(‘echo’, function (data) { io.sockets.emit(‘message’, data); }); }); // Make io … Read more

tech