Tag: socket.io

我怎样才能在套接字1.4中获取套房名称?

我正在寻找一个方法或命令行来获得套房的名字,如果可能的话。 任何想法或提示,高度赞赏! 例如,如果房间的名称是“roomName”,我希望得到这个值,ty!

如何将移动启动的video通话与基于networking的video通话相集成?

我需要使用node.js和支持此function的第三方api来将移动video通话[android / ios]通过networking进行video通话? 我对这一切都不太了解。 请亲切的解释。

variables作用域(module.exports + socket.io设置)

我正在使用node.js , express和socket.io设置websocket应用程序的基础。 我决定将设置socket.io的代码放在一个单独的模块中将是优雅的,所以我的server.js文件可以更小,调用socket.io安装任务的require 。 // server.js // set up ====================================================================== var express = require('express'); var app = express(); var server = require('http').Server(app); var io = require('socket.io')(server); var port = process.env.PORT || 80; // routes ====================================================================== app.get('/', function (req, res) { res.sendFile(__dirname + '/index.html'); }); // socket.io controller ======================================================== require('./app/ws-controller.js')(io); // launch ====================================================================== server.listen(port, function […]

Node.js – 使用sendFile将文件发送到客户端

我对Node.js非常陌生,一直在关注游戏制作教程,在这里可以find: http : //rawkes.com/articles/creating-a-real-time-multiplayer-game-with-websockets-and-node html的 我正在尝试通过将所有必要的文件发送到客户端来改进教程中详细介绍的游戏。 当我连接到我的服务器作为客户端,这个错误是抛出在服务器端, _http_outgoing.js:344 throw new Error('Can\'t set headers after they are sent.'); ^ Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11) at Array.write (/Users/Mark/node_modules/express/node_modules/finalhandler/index.js:164:9) at listener (/Users/Mark/node_modules/express/node_modules/on-finished/index.js:169:15) at onFinish (/Users/Mark/node_modules/express/node_modules/on-finished/index.js:100:5) at callback (/Users/Mark/node_modules/express/node_modules/on-finished/node_modules/ee-first/index.js:55:10) at IncomingMessage.onevent (/Users/Mark/node_modules/express/node_modules/on-finished/node_modules/ee-first/index.js:93:5) at emitNone (events.js:67:13) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:921:12) at nextTickCallbackWith2Args […]

函数的返回值是未定义的

我一直坚持这一段时间,我不知道什么是错的。 我有一个名为Databse.js的单独的类,它运行MySQL函数,它pipe理连接,查询等。我一直试图从它应该返回的1行获取信息(具有正确用户名和密码的用户)但是它说这个variables是未定义的。 如果我在返回它之前logging函数中的对象字段,它们都可以正常工作。 这里是更多的上下文的代码: socket.on('loginAttempt', function(data) { //Check credentials with database… try { var fuser = Database.checkAccount(data.username, data.password); if (fuser === undefined) {//This is always being called console.log("fuser is undefined");//For debug only } } catch(err) { console.log(err.message); } try { if (fuser !== undefined) { socket.emit('loginMessage', {status:true}); socket.id = Math.random(); SOCKET_LIST[socket.id] = socket; var player […]

直接在前端自动更新mongodb的更改,而不使用Node Socket.io和angularjs进行页面刷新

我的问题是,如果我直接在mongodb中手动添加一条消息,如何在活动的UI客户端页面中自动显示而不需要刷新。 我的代码如下。 我的情况是,当新客户端访问页面时,显示mongo中的现有logging,从而保持连接。 但是,如果我直接在mongo里添加一条logging并加载一个新的客户端,那么只有这个logging会有logging,而其他的logging只会在刷新时才会得到。 app.js(服务器端脚本) mongoose.connect("mongodb://localhost:27017/some"); var mschema=mongoose.Schema({ message: String, time : {type:Date ,default: Date.now} }); io.sockets.on('connection', function (socket) { chatmsg.find({},function(err,docs) { if(err) console.log("errorr"); else socket.emit('old msgs',docs); }) socket.on('message', function(message) { var newmsg=new chatmsg({message : message}); newmsg.save(function(err) { if(err) { console.log("error"); } else io.sockets.emit('new message',message) ; }) }) controller.js(客户端脚本) var socket=io("http://localhost:3200"); $scope.sendemit=function() { console.log("inside function"+$scope.textchat); […]

在HTML页面中显示NodeJs的console.log

我有一个服务器app.js和多个客户端,可以连接到我的服务器。 我在index.html显示服务器对客户端的说法,但是我想在客户端与客户端交谈时对服务器执行相同的操作,并在HTML页面中显示我的客户端对服务器所说的内容 。 现在我用console.log()显示它 这里是我的代码 ,我使用的是Socket.io :(我是Javascript新手,这只是一个testing,所以这非常简单) app.js /服务器 : var http = require('http'), fs = require('fs'), // NEVER use a Sync function except at start-up! index = fs.readFileSync(__dirname + '/index.html'); // Send index.html to all requests var app = http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(index); }); // Socket.io server listens […]

在socket.io中调用laravel事件

有可能调用laravel事件并在socket.io中发送一个variables? 这是我想知道的线路是否可以在发送套接字id的套接字中实现: socket.emit('App\\Events\\ClosePlaySession', socket.id); Socket.js var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server, {'pingInterval': 2000, 'pingTimeout': 5000}); var Redis = require('ioredis'); var redis = new Redis(); io.set('heartbeat timeout', 10); io.set('heartbeat interval', 4); server.listen(3000); io.on('connection', function (socket) { console.log("new client connected " + socket.id); socket.on('disconnect', function() { socket.emit('App\\Events\\ClosePlaySession', socket.id); // This is […]

无法发送消息到特定的房间

我想发送消息到特定的房间(所有客户在房间里),我搜查了很多,并尝试这些选项: io.in(socket.RoomId).emit('Test'); io.to(socket.RoomId).emit('Test'); io.sockets.in(socket.RoomId).emit('Test'); 我想作为服务器发送,所以不用在房间里使用现有的sockets。 但是因为我找不到方法,我尝试了以下方法: this.ListOfSockets[0].to(RoomId).emit('Test'); 这不工作,所以我试图只是发射到这个sockets本身: this.ListOfSockets[0].emit('Test'); 而且这个工作正如我所料。 我究竟做错了什么? 为什么我不能作为服务器发送给特定房间的所有客户? 更新2:为li X添加更多的代码 io.on('connection', function(socket){ console.log('client connected'); playerCount++; //For testing purposes I give player random generated string using: var shortid = require('shortid'); socket.id = shortid.generate(); console.log('id of this socket is:' + socket.id); //When client decides to play the game and want's to join a […]

通过websocket添加聊天,到现有的PHPnetworking应用程序

我在标准的PHP / Apache平台上有一个现有的Web应用程序。 现在,我想要的是添加聊天function,我希望它是实时的通过websocket,并扩展我已经研究了一点nodeJs上的socket.io。 因此,除了运行大型PHP应用程序的Apache之外,我还会使用socket.io运行聊天的nodejs。 但是我真的不明白的是,如何在nodejs聊天的代码中识别我的用户呢? 首先,Apache和nodejs将无法在同一个端口上运行,这意味着我将在端口8080上运行聊天,例如,在这种情况下,我丢失了用户的cookies,这意味着我现在必须要求他们login再次在这个nodejs-powered端口,如果他们想使用聊天? 看起来很荒谬,但是我不知道要走哪条路。 当然,我无法将我的整个代码移植到nodejs上。 所以理想情况下,我会希望Apache和nodejs共存。 或者我完全误解了聊天应该如何在networking应用程序中工作。 任何提示赞赏。