Connect to socket.IO from native android
I am developing a service chat for my app and am trying to connect to socket.io from my own android app. I use: -
- https://github.com/nkzawa/socket.io-client.java
- https://github.com/nkzawa/engine.io-client.java
- https://github.com/TooTallNate/Java-WebSocket
my activity class looks like
private Socket socket;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
message = (EditText) findViewById(R.id.editText1);
send = (Button) findViewById(R.id.button1);
try {
socket = IO.socket("http://ridewithme.in:49154/socket");
} catch (URISyntaxException e) {
e.printStackTrace();
}
send.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.button1) {
text = message.getText().toString();
socket.connect();
socket.send(text);
socket.disconnect();
}
}
but I keep getting XHR polling error (logs from Socket.emit ())
com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
com.github.nkzawa.socketio.client.SocketIOException: Connection error
My server is using socket.io v1.0.X and it seems to work fine in the browser. What could be wrong here? Is this a problem of the origin of acces?
+3
source to share
No one has answered this question yet
Check out similar questions: