socket.io emit data by android application to node.js server
NickName:QueUe Ask DateTime:2014-08-31T06:38:50

socket.io emit data by android application to node.js server

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?

Copyright Notice:Content Author:「QueUe」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25587339/socket-io-emit-data-by-android-application-to-node-js-server

Answers
UMESH0492 2014-08-31T11:35:05

i did it like \n\n socket.on(\"new message\", new Emitter.Listener() {\n\n @Override\n public void call(Object... args) {\n\n JSONObject obj = (JSONObject) args[0];\n\n try {//do stuff here}\n catch(Exception){}\n }\n}\n",


QueUe 2014-08-31T11:48:58

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. \nI think the problem is in this line: \n\n`socket.emit(\"sensorChanged\", \"asd\");` \n\n\nbut it looks good. ",


QueUe 2014-08-31T12:18:28

I did it like: \n\n socket = new SocketIO();\n\n try {\n socket.connect(\"http://chat.socket.io\", this);\n } catch (MalformedURLException e) {\n e.printStackTrace();\n }\n\n socket.emit(\"new message\", \"hello TEST\");\n\n\nI 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.",


More about “socket.io emit data by android application to node.js server” related questions

socket.io emit data by android application to node.js server

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...

Show Detail

Socket.IO server does not respond to emit from Android

I am trying to connect with my Node.js Socket.IO server via an Android app. The console log shows that the phone connects with the server but when I try to emit a message from Android, the server d...

Show Detail

Android socket.io application can't connect to node.js server

my application, using socket.io, cant connect to node.js server. server node.js var app = require('http').createServer() var io = require('socket.io')(app); app.listen(1000); io.on('connecti

Show Detail

Android socket.io application can't connect to node.js server

my application, using socket.io, cant connect to node.js server. server node.js var app = require('http').createServer() var io = require('socket.io')(app); app.listen(1000); io.on('connecti

Show Detail

Node.js, Socket.io emit not working

I am making a website in Socket.io. But emit method not working in my code. I can't see any errors in my code. Here is my server code. var io = require("socket.io").listen(server); //Some external

Show Detail

socket emit to nodejs server

I have a Node.js server with socket.io listening on port 4000. I've been able to make javascript version to work just fine and emiting to the socket. Also, I have a Go application that is making some

Show Detail

Node.js socket.io - client emit not seen on server

I'm trying to put together a simple Socket.IO test case in Node.js, but I'm not seeing the events emitted from the client getting to the server. var http = require("http"), io = require("socke...

Show Detail

Why java socket.io emit is fail

i'm creating android application with Socket.io and node.js server. My js server: var http = require('http'); var server = http.createServer(function(req, res) { }); var mysql = require('mysql..

Show Detail

WebSockets for Android in Phonegap application with Node.js/Socket.IO server&client

I am making an Android application in PhoneGap. What I'm trying to do is let the application talk to my Node.js server through WebSockets. My Node.js server uses Socket.IO which automatically falls...

Show Detail

Transmitting data continuously from Chrome for Android to Node.js server using Socket.io

I need to transmit the touch position in Chrome for Android continuously to a Node.js server using Socket.io. However, I guess, the transmission is too fast. The first few values receive the server...

Show Detail