【发布时间】:2016-05-13 17:19:33
【问题描述】:
我在通过 android 应用程序向 node.js 服务器发送数据时遇到问题。
node.js 服务器:
var app = require('http').createServer()
var io = require('socket.io')(app);
app.listen(1000);
app.on('connection', function (client) {
client.name = client.remoteAddress + ':' + client.remotePort;
console.log(client.name + ' connected!');
client.on('sensorChanged', function (data) {
console.log(data);
});
});
它是 Android 应用程序
private TextView txtView;
private SocketIO socket;
try {
socket = new SocketIO("http://localhost:1000");
socket.connect(this);
} catch (MalformedURLException e1) {
txtView.setText(e1.getMessage());
}
socket.emit("sensorChanged", "asd");
当我启动应用程序时,服务器会看到我的手机,但是当我发出事件时,服务器没有响应。 你知道问题出在哪里吗?
【问题讨论】:
-
您找到解决此问题的方法了吗?我也面临同样的问题。