I have problem with emiting data by android application to node.js server.
node.js server:
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);
});
});
and it's Android application
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");
When I start application, server sees my phone, but when I emit event, server dont respond. Do you have any idea where is the problem?
i did it like
socket.on("new message", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject obj = (JSONObject) args[0];
try {//do stuff here}
catch(Exception){}
}
}
I guess it's code from android application. I will use it, but right now I need emit data from Android app to node server. I think the problem is in this line:
`socket.emit("sensorChanged", "asd");`
but it looks good.
I did it like:
socket = new SocketIO();
try {
socket.connect("http://chat.socket.io", this);
} catch (MalformedURLException e) {
e.printStackTrace();
}
socket.emit("new message", "hello TEST");
I dont know what result it should give, but I guess I have to be able see my message on http://chat.socket.io . In this case it doesnt work.