Socket.io本地网络未连接 [英] Socket.io local network not connecting
问题描述
好的,我有以下设置:
问题是计算机2无法通过socket.io连接到计算机1.
是的,我在计算机2中包含了socket.io:
关于为什么计算机2无法在ping的情况下通过socket.io连接到计算机1的任何想法?
其他信息:-Socket.io版本1.4.5-两台电脑都是Windows 10-Phonegap中有Computer 2 JavaScript-计算机2通过wi-fi连接,计算机1通过以太网连接
问候
编辑来自客户端的代码(计算机2,在启动时调用init):
KerstAppHome.prototype.init = function(){var address ='http://192.168.2.120:2017';console.log(正在连接到:" +地址);this.socket = io.connect(address);this.socket.on('connect',this.proxy(function(){console.log(已连接到套接字!");this.socketIsConnected = true;this.socket.on('disconnect',this.proxy(function(){console.log("与套接字断开连接!")this.socketIsConnected = false;}));this.socket.on('musicBlob',this.proxy(this.onMusicBlobReceived))}));};KerstAppHome.prototype.onMusicBlobReceived = function(musicBlob){console.log(接收到的东西");this.audioCtx.decodeAudioData(musicBlob).then(this.proxy(function(audioBuffer){var source = this.audioCtx.createBufferSource();source.buffer = audioBuffer;source.connect(this.audioCtx.destination);source.start();}));}
来自服务器(计算机1)的代码:
var port = 2017;var io = require('socket.io')(port);console.log(正在侦听端口" +端口上的套接字连接);io.on('connection',function(socket){console.log(已建立连接!");socket.on('musicBlob',function(musicBlob){socket.broadcast.emit('musicBlob',musicBlob);});});
来自浏览器(计算机1)的相关代码:
var socket = io.connect('http://localhost:2017');var socketIsConnected = false;socket.on('connect', function(){console.log(已连接到服务器!");socketIsConnected = true;});socket.on('断开', function(){console.log(与服务器断开连接!")$ scope.socketIsConnected = false;});
我想知道为什么计算机2甚至无法连接到服务器,console.log(已连接到套接字!");甚至没有被称为
注意:如果我在计算机1上执行客户端(计算机2)的javascript,它可以正常工作,建立连接并接收数据!
注意:我在计算机1(服务器)上对其防火墙进行了测试,并且防火墙工作正常!
请检查您的防火墙设置,或将其关闭几分钟,然后再尝试连接2台计算机具有相同的lan/wifi.和
允许通过Windows防火墙通过 v8 JavaScript和安全套接字隧道协议使用电话间隙,事件I/O ,
Okay, I have the following setup: https://i.stack.imgur.com/4T9SX.jpg ( If image below is too small )
The problem is that Computer 2 can not connect with socket.io to computer 1.
Yes i included socket.io in computer 2:
Any ideas as to why Computer 2 cannot connect to computer 1 with socket.io whilst ping can?
Extra information: - Socket.io version 1.4.5 - Both computers are windows 10 - Computer 2 javascript is in Phonegap - Computer 2 connects via wi-fi, computer 1 via ethernet
Greetings
EDIT Code from client (computer 2, init is called upon start):
KerstAppHome.prototype.init = function(){
var address = 'http://192.168.2.120:2017';
console.log("Connecting to: " + address);
this.socket = io.connect(address);
this.socket.on('connect', this.proxy(function(){
console.log("Connected to socket!");
this.socketIsConnected = true;
this.socket.on('disconnect', this.proxy(function(){
console.log("Disconnected from socket!")
this.socketIsConnected = false;
}));
this.socket.on('musicBlob', this.proxy(this.onMusicBlobReceived))
}));
};
KerstAppHome.prototype.onMusicBlobReceived = function(musicBlob){
console.log("RECEIVED SOMETHING");
this.audioCtx.decodeAudioData(musicBlob).then(this.proxy(function(audioBuffer) {
var source = this.audioCtx.createBufferSource();
source.buffer = audioBuffer;
source.connect(this.audioCtx.destination);
source.start();
}));
}
Code from server (computer 1):
var port = 2017;
var io = require('socket.io')(port);
console.log("Listening for socket connections on port " + port);
io.on('connection', function (socket) {
console.log("Connection made!");
socket.on('musicBlob', function(musicBlob){
socket.broadcast.emit('musicBlob', musicBlob);
});
});
Relevant code from browser ( computer 1 ):
var socket = io.connect('http://localhost:2017');
var socketIsConnected = false;
socket.on('connect', function(){
console.log("Connected to server!");
socketIsConnected = true;
});
socket.on('disconnect', function(){
console.log("Disconnected from server!")
$scope.socketIsConnected = false;
});
I want to know why computer 2 can't even connect to the server, The console.log("Connected to socket!"); is not even called
NOTE: If I execute the javascript of the client (computer 2) on computer 1, it works perfectly, makes connection and receives data!
NOTE: I tested it with computer 1 (server) his firewall turned off and it worked perfectly!
please check you firewall settings, or turn it off for few minutes and than try, also make sure both 2 computer should be connected with same lan/wifi. and
allow phonegap, Evented I/O for v8 JavaScript and Secure Socket Tunneling Protocol through Windows Firewall,
这篇关于Socket.io本地网络未连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!