Tag: socket.io

无法将socket.io事件转换为Bacon EventStream

在socket.io上的事件绑定下面工作正常, io = require('socket.io')() io.on 'connection', (socket) -> console.log socket.id io.listen 3000 然后尝试将socket.io event转换为Bacon EventStream , Bacon = require('baconjs').Bacon io = require('socket.io')() connections = Bacon.fromEventTarget io, 'connection' connections.onValue (socket) -> console.log socket.id io.listen 3000 为什么在下面失败? TypeError: Object connection has no method 'on'

在Express中停止执行取消的请求

我正在创build一个应用程序,这个应用程序会向另一个服务器发出大量的HTTP请求,而完成这样的请求可能需要1分钟的时间。 有些用户取消了请求,但我的应用程序仍然执行取消的请求。 这是我的代码: var app = express(); app.get('/something', function (req, res) { function timeout(i) { setTimeout(function () { // lets assume there is a http request. console.log(i); timeout(++i); }, 100); } req.connection.on('close', function () { console.log('I should do something'); }); timeout(1); }); app.listen(5000); 基本上,我想要的是停止console.log(i)在客户端closures连接后调用。 另外,如果可能,客户端省略“close- {id}”事件,当后端收到close- {id}事件时,它终止{id}请求。 注意:我使用setTimeout来显示callbackmechanizim。 这不是真正的代码。 感谢您的帮助。

socket.io可以处理多less个房间?

我正在使用socket.io构build一个应用程序 我正在使用socket.io的房间function,有5个“主题”用户可以订阅。 在该主题中广播的每个消息都具有消息types,其中有100个。用户将只接收它们允许接收的types的消息,该消息可以在30到70之间。 我的问题是:为每个话题+消息types组合创build一个空间是可行的,这个组合将是5×100个房间? 请问socket.io的性能如何,还是有更好的方法来解决这个问题? 将单个消息发送到每个单独的套接字,而不是使用房间,会更好? 谢谢你的帮助。

如何维护socket.io + node.js中的当前活动套接字?

我开始学习socket.io和node.js我试图做一些非常基本的东西(或者我想),但我无法做到。 这是我的节点应用程序: var app = require('http').createServer(handler) , io = require('socket.io').listen(app) , fs = require('fs') app.listen(8080); var clients = []; function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { clients[socket.id] = true; socket.broadcast.emit('conection', { id: clients}); […]

如何获取用户的套接字客户端?

我正在实现一个node.js服务器,它使用socket.io(版本:0.8.7)pipe理用户之间的双向连接。 我使用一个数组存储没有聊天伙伴的用户。 当用户请求一个新的合作伙伴时,应用程序将挑选该arrays中的用户,然后检查用户是否仍然连接。 这是我的问题: 即使用户仍然连接,我无法为用户获取套接字客户端。 这是我的代码片段: // An array of users that do not have a chat partner var soloUsers = []; var io = sio.listen(app); io.sockets.on('connection', function (socket) { socket.on('sessionStart', function (message) { // Parse the incoming event switch (message.event) { // User requested initialization data case 'initial': … // User requested next partner […]

将hexstring转换为BYTE数组JS

我一直在这一点,我是与JS编程新。 我正在使用JS,HTML5,节点和socket.io进行游戏。 我现在正在协议,我发送hex的服务器string。 一个string的例子是:00010203040506070809 我很难将其转换为:0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 我打算做的是采取这些自定义数据包,并根据数据包在我的服务器上有一个开关。 举个例子: BYTE HEADER | + Packet 0x00 | 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 然后我调用:parsepacket(header,data,len); function parsepacket(header, data, len){ switch(header) { case '0x00': // not hexed console.log('The client wants to connect'); // Do some stuff to connect […]

nodejs / socket.io与node-mysql | 安全混乱

所以我开始研究node-mysql,因为我的整个站点都是用PHP构build的,但是我想用node / socket.io来实现平滑的asynchronous用户端更新。 然而,有一个问题,我看到与node-mysql,我还没有得到一个答案呢。 mysql服务器的login信息如何不公开信息? 根据文档https://github.com/felixge/node-mysql你连接到数据库就像这样 var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'me', password : 'secret', }); connection.connect(); connection.query('SELECT 1', function(err, rows, fields) { if (err) throw err; console.log('Query result: ', rows); }); connection.end(); 那么是什么阻止用户将服务器文件放入导航栏并查看mysql服务器的login信息呢? 我对此感到非常困惑,有人可以向我解释吗?

AppFog node.js客户端无法加载socket.io

我只是将一个node.js站点部署到AppFog。 当我去“http:// localhost:8080”时,它在本地工作正常,但是当我到达AppFog上的一个: http ://bandwithfriends.aws.af.cm/时,我得到以下Chrome控制台错误: XMLHttpRequest cannot load http://localhost:8080/socket.io/1/?t=1357769454152. Origin http://bandwithfriends.aws.af.cm is not allowed by Access-Control-Allow-Origin. 服务器代码: var app = require('http').createServer(handler), io = require('socket.io').listen(app), static = require('node-static'); // for serving files // This will make all the files in the current folder // accessible from the web var fileServer = new static.Server('./'); app.listen(process.env.VCAP_APP_PORT || 8080); […]

套接字将消息发送给房间中的用户

我正在使用nodejs和socketio。 我做了一个私人聊天应用程序发送消息给选定的用户。 我目前的代码是: chat_room.sockets.socket(user).emit( 'chat', { message : message, from : sockets[socket.id].username } ); 现在我创build了房间,我想发送消息给特定房间的用户。 我尝试下面的代码,但不工作 socket.get('room', function(err, room) { chat_room.sockets.socket(room)(user).emit( 'chat', { message : message, from : sockets[socket.id].username } ); }); 它的错误,它给了我一个错误: C:\ Users \ Niraj \ Desktop \ node \ joomla-chat \ app.js:62 chat_room.sockets.socket(room)(user).emit(^ TypeError:object不是chat_room.sockets.on.socket的函数Client.get(C:\ Users \ Niraj \ Desktop \ node \ […]

在浏览器中保存所有打开的选项卡的socket.io ID

你可以告诉如何解决保存身份socket.io ,浏览器中的所有打开的标签的问题。 例: 我打开了一个页面(例如/index ),我将它设置为连接到socket.io并获取唯一的会话ID。 但是当我在另一个选项卡上打开相同的页面 – ID创build另一个,也就是说,已经有两个具有两个不同ID的化合物。 这是对的,这是合乎逻辑的。 但是,我需要发送消息到这些ID,同时在所有选项卡(包括绑定到user_id ),因为会话ID是不同的 – 这是不可能的。