Socket.IO

socket.on event gets triggered multiple times

我们两清 提交于 2020-01-03 18:42:28
问题 var express = require('express'); var app = express(); var server = app.listen(3000); var replyFromBot; app.use(express.static('public')); var socket = require('socket.io'); var io = socket(server); io.sockets.on('connection' , newConnection); function newConnection(socket) { console.log(socket.id); listen = true; socket.on('Quest' ,reply); function reply(data) { replyFromBot = bot.reply("local-user", data); console.log(socket.id+ " "+replyFromBot); socket.emit('Ans' , replyFromBot); } } i've

Python Client to nodeJS Server with Socket.IO

前提是你 提交于 2020-01-03 16:44:52
问题 I'm trying to send values from my raspberry pi (in python 2.7.9) to my nodeJS server with socket.io. My goal ist send many values continuously from my pi over a websocket connection to my node Server (local), which should take the values and show it on the index.html (for other clients, like a Web-Chat where just the raspberry sends values) I tried everything but I can't make a handshake and send data. When I open the "http://IP_ADDRESS:8080" in my browser I see a connection but not with my

socket.io - ReferenceError: socket is not defined

丶灬走出姿态 提交于 2020-01-03 15:55:13
问题 I'm trying to write a simple app that mirrors each character I type in a text area onto a div using socket.io, but I keep getting the following client error: "ReferenceError: socket is not defined" Here's my server code: var express = require('express'), app = express(), server = require('http').createServer(app), io = require('socket.io').listen(server); server.listen(3000); app.get('/', function(req,res){ res.sendfile(__dirname+ '/index.html'); }); io.sockets.on('connection', function

Socket.io reconnect on disconnect?

我的梦境 提交于 2020-01-03 14:08:51
问题 Is something like this possible? socket.on('disconnect', function(){ console.log('disconnected...'); socket.connect(); socket.on('connect', function(){ console.log('...reconnected'); }) }) 回答1: Socket.io reconnects automatically (if you set the reconnect option, although it defaults to true), so you don't really need to do that. Furthermore, there is a reconnect event which seems far more appropriate. Also, set your event handlers independently, don't set the connect handler in the execution

Proxying WebSocket connections and ephemeral port exhaustion

安稳与你 提交于 2020-01-03 12:22:07
问题 I'm designing an application that make will use of WebSocket to notify visitors quickly when changes occur. I'm planning to proxy the connections with Nginx, so they can share the same address as the regular HTTP portion. One thing I'm concerned about is the exhaustion of ephemeral ports. In the past, I have noticed problems when the number of connections between Nginx and the Node backend exceeds 25000. My question is, would the following config increases the limit to 100K? upstream backends

NodeJS-socket.io getting “Access is Denied” Exception

纵饮孤独 提交于 2020-01-03 05:52:47
问题 I have a node (0.6.11)/socket.io(0.9.0) application that runs well in FF but IE8 throws JS exceptions: Access is denied in socket.io.js (line 2561): req.open(method || 'GET', this.prepareUrl() + query, true); a few lines before that, req is defined as req = io.util.request(this.socket.isXDomain()) This suggests it is a cross domain issue, but I'm doing it locally all the way. Plus FF has no issues. What could be the cause? . Here's the source code: SERVER: var app = require('express')

Updating client-side JS application in real-time based on admin activity (in JS, PHP, or 3rd party widget)

北城以北 提交于 2020-01-03 05:35:50
问题 I've coded a web app in Laravel (PHP). Let's call it example.com. I'd like (as an admin) to have a button that toggles in real-time the visibility of an element example.com. That is, public visitors who are looking at example.com could see the effect of the button that I pressed even if they never refresh the page . It seems that this would be possible via something like Pusher and https://laravel.com/docs/6.x/broadcasting (or WebSocket or WebRTC?). The JS in the client would have: Echo

socket.io no communication between server and client

半城伤御伤魂 提交于 2020-01-03 05:20:14
问题 I'm currently trying to have an angular2 frontend communicating with a node.js backend with socket.io. The point is, I get the client connected to the server, but after that, no socket call can be successfully passed between them. Here is a simple piece a code for the server : var app = require('express')(); var http = require('http'); var server = http.createServer(app); var io = require('socket.io').listen(server); io.on('connection', function() { io.emit('update'); console.log('Connected')

Newrelic + node.js + socket.io

旧城冷巷雨未停 提交于 2020-01-03 05:13:09
问题 Newrelic announced support for node.js applications on Oct 24, 2013. I set up monitoring for my node.js server. It is a service that talks to Client via socket.io. Now, all the requests like this /socket.io/*/xhr-polling/40pt1SBvasfDuwctz4Ma for the service appear to take 20.000 seconds. Is there a way to set up newrelic so it would correctly show request times served by socket.io? 回答1: New Relic gives you the option to ignore a rule for something exactly like this. For example you would want

cordova/phonegap : cannot connect to socket.io

这一生的挚爱 提交于 2020-01-03 04:57:10
问题 My application works fine on browser. When I compile it with intelXDL / phonegap : AJAX calls works fine, but not socket.io connections. (sockets use port 1445) I have "status: cancelled" so it looks like permissions problem I tried to add ALL possible combinations for whitelist (I use CLI 4.1.2) http://www.example.com/* http://www.example.com:1445/* http://*:1445/* http://* * The first rule makes AJAX call possible. The other rules do not allow to connect to socket.io on port 1445 Any idea ?