I am trying to connect an android app to Socket.io server on MEAN Stack.
I am emitting a test string on socketTesting and listening on the server side.
MainActivity.java
public class MainActivity extends ActionBarActivity {
TextView tv;
private Socket socket;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
socket = IO.socket("http://"+IP_ADDRESS+":"+PORT_NO);
} catch (URISyntaxException e) {
e.printStackTrace();
}
socket.connect();
socket.emit("socketTesting","hiiii");
setContentView(R.layout.test_xml);
}
@Override
public void onDestroy() {
super.onDestroy();
socket.disconnect();
}
}
This is the server side code:
socket.on('socketTesting', function(message) {
console.log(JSON.stringify(message));
});
Nothing is displayed on the server side. I know this is a very basic question but i've looked around much without any success. There's no exception thrown and neither does it connect.