How to authenticate the socket?

87 Views Asked by At

I'm using Socket Cluster and I (here the link enter link description here) have an OAuth app. So I'm getting nullPointerException in socket.connect() method. Here the syntax.

private String url = "http://There's my Ip and port";
private Socket socket;

public void connect(final String token) {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            socket = new Socket(url);
            socket.setAuthToken(token);
            socket.connect();

            if (socket.isconnected()) {
                Toast.makeText(act, "Socket connected successfully", Toast.LENGTH_SHORT).show();
            }
        }
    });

    thread.start();

}

You see the token in constructor? I'm calling this method in class where I'm doing the retrofit call, and when I got the access token, I'm giving it there. In socket.connect() it gives nullPointerException.

1

There are 1 best solutions below

0
On

Do you have the Internet Permission in manifest?

    <uses-permission android:name="android.permission.INTERNET" />