iam new in node.js and socket.io i developing sample socket.io project and i want passing argument to connection event and cordova app that connect to socket.io server
its work fine in local host but error in server i should add it, after connection event successful, supposed to post request well
i tried many solution but dosnt work
Failed to load resource: the server responded with a status of 404 (Not Found) http://37.220.11.252/socket.io/socket.io.js
GET http://37.220.11.252:3000/socket.io/?username=0912101&EIO=3&transport=polling&t=Lg_3duf net::ERR_CONNECTION_TIMED_OUT socket.io.js
on server
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var rest = require('restler');
var serverpath = 'http://37.220.11.252';
var userconnectiondata =
{
username: '',
cred: '',
socketid: ''
}
var connectionlist = [];
server.listen(3000);
console.log("server running");
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
io.use(function (socket, next) {
var userconnectiondata =
{
username: socket.handshake.query.username,
cred: socket.handshake.query.cred,
socketid: socket.id
}
console.log('con %s', socket.id);
connectionlist.push(userconnectiondata);
var jsonData = {
username: userconnectiondata.username,
SocketID: userconnectiondata.socketid
};
rest.postJson(serverpath + '/Chat/UpdateSocketId', jsonData).on('complete', function (data, response) {
// handle response
});
next();
socket.on('disconnect', function (data) {
for (var i = 0; connectionlist.length; i++) {
if (connectionlist[i].socketid == socket.id) {
connectionlist.splice(i, 1);
break;
}
}
console.log('discon %s', socket.id);
});
});
in client
<script src="http://37.220.11.252/socket.io/socket.io.js"></script>
var temp = "username=0912101" ;
socket = io("http://37.220.11.252:3000", {
query: temp
});
i appreciate any help my firends
via navid gharehkhanian
No comments:
Post a Comment