【发布时间】:2014-08-31 13:28:36
【问题描述】:
我的应用程序,使用 socket.io,无法连接到 node.js 服务器。
服务器节点.js
var app = require('http').createServer()
var io = require('socket.io')(app);
app.listen(1000);
io.on('connection', function (client) {
client.name = client.remoteAddress + ':' + client.remotePort;
console.log(client.name + ' connected!');
client.on('sensorChanged', function (data) {
console.log("HERE");
console.log(data);
});
});
安卓应用:
SocketIO socket = new SocketIO();
try {
socket.connect("http://localhost:1000/", this);
txtView.setText("connected");
} catch (MalformedURLException e) {
e.printStackTrace();
}
socket.emit("sensorChanged", "argument1");
当我连接到服务器时,服务器不会说“socket.name connected”,也不会发出事件“sensorChanged”。问题出在哪里?
【问题讨论】: