Tag: socket.io

Socket.io不发送消息给XHR客户端

好的,我有一个运行Socket.io的Node.js服务器。 它使用RedisStore,所以我可以有多个Node.js服务器实例。 一切正常,因为我不能从服务器发送消息到我的XHR轮询客户端的例外。 它在以下情况下运行良好: 在Chrome中testing客户端并使用Websockets时,效果很好。 连接到同一个节点服务器实例时。 因为我使用RedisStore,所以它应该工作,不pipe它在哪个实例上。

socket.io在241个客户端ENOTFOUND

我正在尝试对我的socket.io服务器进行基准testing,当我注意到一旦build立了241个并发连接,客户端就收到ENOTFOUND错误。 但是,我正在阅读其他网站上关于1000多个客户端的并发。 我正在使用一台3GHz和16GB RAM的机器进行testing,这个机器几乎没有使用。 所以我不确定为什么连接失败。 有谁知道为什么服务器不再那么快? 我正在使用节点:v0.10.28和socket.io:0.9.17 { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', target: { _socket: null, bytesReceived: 0, readyState: 0, supports: { binary: true }, _isServer: false, url: 'ws://localhost:3001/socket.io/1/websocket/FvzSa7LmLu0Toi7F6OZF', protocolVersion: 13, _events: { open: [Object], message: [Object], close: [Object], error: [Object] } } }

如何closuressocket.io 1.0中的服务器?

有一些这样的,但他们是以前版本的图书馆。 看来代码已经改变了。 我正在实例化一个套接字,如下所示: this.socketLib || (this.socketLib = require('socket.io')); this.socket = this.socketLib.listen(this.port); 在对象的其他地方,我有一个closuresfunction。 我试过以下closures套接字: this.socket.close() # TypeError: Object #<Server> has no method 'close' this.socket.server.close() # TypeError: Object #<Server> has no method 'close' this.socket.server.disconnect() # TypeError: Cannot call method 'disconnect' of undefined this.socket.disconnect() # TypeError: Object #<Server> has no method 'disconnect' this.socket.io.engine.close() # TypeError: Cannot read property […]

Socket.io 1.0内部发射事件

套接字0.9和更早 以前在Socket.io 0.9中,在命名空间下有一个暴露的方法: $ emit(…) ,它允许你使用NodeJS EventEmitterfunction绑定事件。 io.of('namespace').on(…) 这可以用来在同一个socket.io中发送事件,而不需要做任何types的外部客户端或其他方法。 Socket.io 1.0 它出现在Socket.io 1.0中,这被删除了,以支持一个私有variables 。 有没有官方的方法或最好的方式来发送和接收在同一个应用程序中的socket.io事件,而无需使用socket.io-client并连接到服务器? 解决方法 我现在通过创build自己的callback注册来解决这个问题,但我更愿意使用socket.io来内部侦听它自己的事件并使用它的命名空间。 socketIO.register = function(event, callback){ socketIO.registeredEvents = socketIO.registeredEvents || {}; socketIO.registeredEvents[event] = socketIO.registeredEvents[event] || []; socketIO.registeredEvents[event].push(callback); }; socketIO.emitInternal = function(event, eventData){ if(!socketIO.registeredEvents[event] || socketIO.registeredEvents[event].length === 0) return; socketIO.registeredEvents[event].forEach(function(callback){ callback(eventData); }); };

发布设置Pubnub Nodejs服务器

以下面的示例为例: https : //www.npmjs.org/package/pubnub 我试图build立从我的nodejs服务器连接到pubnub通过: var pubnub = require("pubnub").init({ publish_key: "pub key here", subscribe_key: "sub key here", channel: 'my_channel', user: 'Server' }); pubnub.subscribe({ channel: 'my_channel', callback: function(message) { console.log("Message received: ", message); } }); pubnub.publish({ channel : 'my_channel', callback : function(e) { console.log( "SUCCESS!", e ); }, error : function(e) { console.log( "FAILED! RETRY PUBLISH!", […]

Node.js:Socket.io 0.9.17 – 带宽使用

我正在使用Node.js(v0.10.29)和Socket.io(v0.9.17)。 我无法将Socket.io升级到v1.0.6,因为我需要与Android设备进行通信,目前似乎还没有任何一个解决scheme可以更新到Socket.io v1.0。 我的问题是,使用Socket.io v0.9.17时,使用的带宽非常高。 作为一个例子,对于相同的数据量,Socket.io v0.9.17使用800KB,当Socket.io v1.0.6使用8KB … 有没有人知道为什么? 我能做些什么来避免这种情况? 谢谢

如何与socket.io捆绑快速会话

如何使用socket.io将expression式4中的会话关联起来,这样会话数据既可以被检索到,也可以被双向保存。 socket.io中的身份validation是基于标记的jwt 相同的套接字在多个虚拟主机中共享 例如: global.socket.of('/secure').on('connection', function(socket){ console.log('client connected to "secure" socket'); }); app.js var port = 3000, jwtSecret = '26fed98d8c6c7c54f485f1ee7ffe44d2e1feae28'; var app = require('express')(), vhost = require('vhost'), server = require('http').createServer(app), socketioJwt = require('socketio-jwt'); // Start server with socket.io global.socket = require('socket.io').listen(app.listen(port, function(){ console.log('Express server listening on port '+port); })); // Socket authentication global.socket.set('authorization', socketioJwt.authorize({ secret: […]

Socket.IO授权不刷新

在第一次调用本地主机时,它发送index.html并尝试授权。 授权当然是不被批准的。 在用户完成后,在index.html中填写一个表单“app.post('/ login'…”被执行。 我现在想要的是,login后的授权将被执行一次,客户端与Socket.IO连接。 那可能吗? 或者我必须在客户端login后刷新页面? app.post('/login', function(req, res) { req.session.status = { test:111 }; res.end(); }); app.get('/', function(req, res){ res.sendfile(__dirname + '/index.html'); }); io.set('authorization', function(req, callback) { console.log("hi"); // check if user is logged, if yes connect with socket.io }); io.sockets.on('connection', function(socket){ });

最佳实践socket.io广播消息

目前我们正在尝试编写一个应用程序来对多个数据库环境(MSSQL,DB2,Oracle)进行健康检查。 已经编写了一个web服务来执行健康检查查询,该查询返回响应时间。 我认为,而不是一个Web客户端连接到Web服务来返回数据库状态,使用一个节点的socket.io服务器来运行web服务,并将结果推送到所有的webclient会更好,因为健康检查的开销数据库将是最小的(在50人同时使用web应用程序的情况下,每5秒钟只进行一次web服务调用,而不是同时进行50次web服务请求)。 这样,即使有一百万人在使用networking应用程序,数据库也不应受到任何影响。 (虽然会降低节点服务器。) 这是代码的套接字面。 我是新来的节点和套接字。 我的下一步是将结果logging在本地MongoDB中,并只广播更改(仅响应时间)而不是所有内容,以减lessnetworkingstream量并可能绘制历史结果。 我想知道是否有可能的socket.io断开连接,如果客户端有多个标签,它的浏览器和Web应用程序不是“聚焦”,并重新连接到一旦标签再次聚焦套接字。 只是想知道这是一个好方法还是有更好的方法来实现我的目标? 另外,将我的web应用程序放置在与节点套接字服务器相同的服务器中是否是一个好主意,或者将它们分开会更好? var express = require('express') , http = require('http'); var app = express(); var server = app.listen(3030); var io = require('socket.io').listen(server); var allClients = []; io.sockets.on('connection', function(socket) { allClients.push(socket.client.id); console.log(allClients); socket.on('disconnect', function() { var i = allClients.indexOf(socket.client.id); console.log(allClients[i] + ' is disconnect!'); delete allClients[i]; allClients […]

Socket.io / Node.js:来自客户端的套接字连接上的“值超出范围”

我正在使用ARMv5TE处理器上的busybox linux上运行nodejs / socket.io / express。 我有nodejs启动并运行,下面的代码运行没有错误。 var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server); server.listen(80); app.get('/', function (req, res) { res.sendfile(__dirname + '/index.html'); }); io.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); 直到我尝试通过websocket从客户端连接。 从浏览器(加载客户端脚本socket.io.js ), var socket = io.connect('ws://192.168.1.8:3000'); 或者var […]