i using socket io node manage chat application
i can connect socket , , when connect other other machine , client not recive .
in other machine , there no antivirus , firewall disabled . ( use google chrome , opera , windows 7 )
something interesting can connect socket mobile !
when machine connect system , can see debug in console
info - socket.io started debug - served static content /socket.io.js debug - served static content /socket.io.js debug - client authorized info - handshake authorized gu63jd6tynpcf7jo72u0 debug - setting request /socket.io/1/websocket/gu63jd6tynpcf7jo72u0 debug - set heartbeat interval client gu63jd6tynpcf7jo72u0 debug - client authorized debug - websocket writing 1:: **debug - websocket writing 5:::{"name":"ready","args":[{"msg":"hi"}]}** debug - setting request /socket.io/1/xhr-polling/gu63jd6tynpcf7jo72u0?t=1374596975155 debug - setting poll timeout debug - discarding transport debug - cleared heartbeat interval client gu63jd6tynpcf7jo72u0 debug - setting request /socket.io/1/jsonp-polling/gu63jd6tynpcf7jo72u0?t=1374596985158&i=0 debug - setting poll timeout debug - discarding transport debug - clearing poll timeout
i use connect site :
var socket = io.connect('192.168.1.101:900');
the machine not 404 not found , or error , methods did not fire...
as can see , client should receive ready , not , problem ?
the server source :
var express = require('/usr/local/lib/node_modules/express'), app = express() , http = require('http') , server = http.createserver(app) , io = require('/usr/local/lib/node_modules/socket.io').listen(server); // listen new web clients: server.listen(900, function() { //console.log(this); }); // routing app.get('/', function(req, res) { res.end('it works'); }); io.sockets.on('connection', function(socket) { socket.emit('ready', {msg: 'hi'}); }
client
var socket = io.connect('192.168.1.101:900'); console.log('connecting'); socket.on('error', function(data) { console.log(data || 'error'); }); socket.on('connect_failed', function(data) { console.log(data || 'connect_failed'); }); // on connection server, ask user's name anonymous callback socket.on('connect', function() { alert('work'); }); socket.on('ready', function() { alert('work'); });
Comments
Post a Comment