Socket io and android not connecting

1k views Asked by At

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.

1

There are 1 answers

0
n_rao On

1) check the socket.io version matches. Because of socket.io mismatch between server and client i received transport error(spent 2 days to realize).

2) If your socket is listening on port 80, Then open browser and enter http://your-server-ip:80 which will give json reply if the server socket is open for connection.

3) ppl use DEBUG=* node your-file.js to get the current status , It prints out everything .(check google for more info)