Prise en manque de gestionnaire d'erreur de socket message à l'aide de Node.js et de la Prise.io

Salut, j'obtiens l'erreur suivante qui exécutent le serveur à l'aide de Node.js et de la prise.io.

Erreur:

Missing error handler on `socket`.
TypeError: Cannot read property 'connected' of undefined
at Socket.<anonymous> (C:\Documents and Settings\Subhrajyoti\Desktop\Restore
\htdocs\video broadcast\server.js:68:13)
at Socket.emit (events.js:95:17)
at Socket.onevent (C:\Documents and Settings\Subhrajyoti\Desktop\Restore\htd
ocs\video broadcast\node_modules\socket.io\lib\socket.js:330:8)
at Socket.onpacket (C:\Documents and Settings\Subhrajyoti\Desktop\Restore\ht
docs\video broadcast\node_modules\socket.io\lib\socket.js:290:12)
at Client.ondecoded (C:\Documents and Settings\Subhrajyoti\Desktop\Restore\h
tdocs\video broadcast\node_modules\socket.io\lib\client.js:193:14)
at Decoder.Emitter.emit (C:\Documents and Settings\Subhrajyoti\Desktop\Resto
re\htdocs\video broadcast\node_modules\socket.io\node_modules\socket.io-parser\n
ode_modules\component-emitter\index.js:134:20)
at Decoder.add (C:\Documents and Settings\Subhrajyoti\Desktop\Restore\htdocs
\video broadcast\node_modules\socket.io\node_modules\socket.io-parser\index.js:2
47:12)
at Client.ondata (C:\Documents and Settings\Subhrajyoti\Desktop\Restore\htdo
cs\video broadcast\node_modules\socket.io\lib\client.js:175:18)
at Socket.emit (events.js:95:17)
at Socket.onPacket (C:\Documents and Settings\Subhrajyoti\Desktop\Restore\ht
docs\video broadcast\node_modules\socket.io\node_modules\engine.io\lib\socket.js
:99:14)

Mon côté serveur de code est donné ci-dessous.

Server.js:

var port=8888;
var express=require('express');
var morgan = require('morgan');
var http=require('http');
var bodyParser= require('body-parser');
var methodOverride = require('method-override');
var mongo = require('mongojs');
var database='Oditek';
var collections=['video'];
var app= express();
var server=http.Server(app);
var io=require('socket.io')(server);
var db = mongo.connect("127.0.0.1:27017/"+database, collections);
app.use(express.static(__dirname + '/public'));     //set the static files location /public/img will be /img for users
app.use(morgan('dev'));                     //log every request to the console
app.use(bodyParser.urlencoded({ extended: false }))    //parse application/x-www-form-urlencoded
app.use(bodyParser.json())    //parse application/json
app.use(methodOverride());                  //simulate DELETE and PUT
db.on('ready', function () {
console.log('database connected')
});
app.get('/',function(req,res){
res.sendfile('view/login.html');
});
app.post('/login',function(req,res){
var username=req.body.username;
var password=req.body.userpassword;
if(username && password){
db.video.findOne({
username:username,
password:password
},function(err,doc){
if(doc){
console.log('login',doc);
res.send(doc);
}
if(err){
console.log('login12',err);
res.send("could not login");
}
});
}
});
app.get('/video',function(req,res){
res.sendfile('view/video.html');
});
//socket----programming//
var roomid;
var clients={};
io.sockets.on('connection',function(socket){
//console.log(socket);
roomid=socket.handshake.query.roomid;
var usertype=socket.handshake.query.usertype;
socket.on('admin-join',function(data){
console.log('admin',data);
if(data.IsJoinAdmin){
clients={
"socket":roomid
}
socket.join(roomid);
}
});
socket.on('user-join',function(data){
console.log('user',data);
if(data.isUserJoin){
io.socket.connected[clients.socket].emit('user-already-joined',data);
socket.join(roomid);
}
});
socket.on('send-broadcasting-message',function(data){
console.log('message',data)
io.to(roomid).emit('sending-broadcasting',data);
});
});
server.listen(port);
console.log('server is listening on the port'+port);

Je suis d'erreur à cette ligne io.socket.connected[clients.socket].emit('user-already-joined',data);.Cette ligne, je suis à l'aide d'envoyer un message privé à un utilisateur particulier.Merci de m'aider à résoudre cette erreur.

La version de la prise.io utilisez-vous?
Edgae : socket version 1.3.5

OriginalL'auteur satya | 2015-07-31

Leave a Reply

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *