Socket.IO

get client ip of the request in net library nodejs

本小妞迷上赌 提交于 2020-01-17 04:26:06
问题 I am using sticky session in nodejs which is behind nginx. Sticky session does the load balancing by checking the remoteAddress of the connection. Now the problem is it always take ip of nginx server server = net.createServer({ pauseOnConnect: true },function(c) { // Get int31 hash of ip var worker, ipHash = hash((c.remoteAddress || '').split(/\./g), seed); // Pass connection to worker worker = workers[ipHash % workers.length]; worker.send('sticky-session:connection', c); }); Can we get the

Socket IO 1.x server library for python

情到浓时终转凉″ 提交于 2020-01-17 04:26:04
问题 is there any socket io 1.x server library for python? I have found https://github.com/miguelgrinberg/Flask-SocketIO but only support for socket io version 0.9.16, this is the author say : Please do not use the new socket.io 1.0 client libraries, that is a very recent release that is likely not supported by project gevent-socketio. Please use 0.9.16 for now. https://github.com/miguelgrinberg/Flask-SocketIO/issues/33 Please help me :) 来源: https://stackoverflow.com/questions/29428273/socket-io-1

Socket.io socket property not found in disconnect event, node.js

╄→尐↘猪︶ㄣ 提交于 2020-01-16 18:36:52
问题 I have a small but annoying problem that I can't find the solution for. On the server side I have this: ... socket.on('join', function (name) { console.log("Joining: "+name); socket.userName = sanitize(name); } socket.on('msg', function(m) { console.log(socket.userName+" says: "+m);//This works }); socket.on('disconnect', function(socket) { console.log(socket.userName+" has disconnected");//This does not work }); ... The issue is that the socket.userName is available in all my .on methods

Socket.io socket property not found in disconnect event, node.js

好久不见. 提交于 2020-01-16 18:35:47
问题 I have a small but annoying problem that I can't find the solution for. On the server side I have this: ... socket.on('join', function (name) { console.log("Joining: "+name); socket.userName = sanitize(name); } socket.on('msg', function(m) { console.log(socket.userName+" says: "+m);//This works }); socket.on('disconnect', function(socket) { console.log(socket.userName+" has disconnected");//This does not work }); ... The issue is that the socket.userName is available in all my .on methods

How to add parameters to a FeathersJS socket connection

这一生的挚爱 提交于 2020-01-16 17:07:29
问题 I'm developing an app that uses a FeathersJS server, and an Electron app that uses FeathersJS Socket.io client to connect to the server. I'd like to use channels in the Electron app to get notified when some data in the server has changed. The Electron app is an "autonomuos" app, so there isn't any user authentication or interaction. The Electron app will have a unique id that represents each machine it is running on. Taking into account that there isn't any kind of authentication, how can I

Socket.io: How to calculate count of websockets online using callbacks of “connection” and “disconnect” events (or another events)?

怎甘沉沦 提交于 2020-01-16 12:18:17
问题 I need to get count of websockets online. I trying to calculate this that: const socketIo = require('socket.io'); const app = require('express')(); const http = require('http').Server(app); var online = 0; var port = 6001; var io = socketIo(port); //I have only one NameSpace and root NS is not used var ns1 = io.of('ns1'); ns1 .on('connection', function (socket) { online += 1; socket.on('disconnect', function (reason) { online -= 1; }); }); ... app.get('/', function (req, res) { res.send({

How to disconnect a client for being inactive in chat for a specific time (socket.io, javascript)

夙愿已清 提交于 2020-01-16 09:41:30
问题 In this chat app I want the server to disconnect clients who's been inactive for x (configurable) amount of time. I think the default is 60 sec, I think I should use page Timeout as you can see in my server file but not sure how to make it work. The idea is to have a timer for let's say 2 minutes of inactivity and you get kicked out with a message appearing afterwards in the feedbackBox function in name.js file. My code is below: server.js const PORT = 3000; const io = require('socket.io')

Player movement in javascript with socket.io

徘徊边缘 提交于 2020-01-16 08:57:08
问题 Im currently making a html5 multiplayer game with socket.io. My problem is that i can only move my character in a straight line, while i also want to be able to move diagonal across my canvas. What i mean by this is if i press the 'a' and 'd' key, my character moves diagonally to the bottom right. With my current code my character only moves to the right or down. //client, how i capture my keyboard input. document.onkeydown = function(event){ console.log(`Keycode: ${event.which}`); if(event

Player movement in javascript with socket.io

一笑奈何 提交于 2020-01-16 08:57:05
问题 Im currently making a html5 multiplayer game with socket.io. My problem is that i can only move my character in a straight line, while i also want to be able to move diagonal across my canvas. What i mean by this is if i press the 'a' and 'd' key, my character moves diagonally to the bottom right. With my current code my character only moves to the right or down. //client, how i capture my keyboard input. document.onkeydown = function(event){ console.log(`Keycode: ${event.which}`); if(event

How to connect socket.io with a Heroku-deployed React Native app?

风格不统一 提交于 2020-01-16 08:45:15
问题 I have almost googled my fingers off trying to figure this out. It seems a lot of the existing info on connecting socket.io with React Native is outdated, or maybe I'm just interpreting things wrong? I've managed to get the client-side connected (I'm getting the client console logs when I connect to my app). It seems to be the server-side that's giving me issues. Why is the data being emitted from the client not showing up as a log in my terminal? None of the related console.logs in my server