Skip to content

Socket Basic Listener does not receive messages in few phones. #43

Description

@aalap03

I am using this code to listen to the socket messages from our server.

Issue is I am testing with 2 samsung galaxy S7Edge phones both API level 26 and it one phone the socket messages works and in other phone it does not. Another test phone I am working with is Samsung S5 Neo with API 24 and it works with that phone.

I have looked into the the phones notification settings but it looks good.

Please let me know what phone settings I need to look at or what is the issue in the below code on setting the SocketClusterService.

Library Version: 1.7.5

public class SocketClusterService extends IntentService implements BasicListener {


private static final String SERVER_URL = "url"
Socket socket;
Socket.Channel channel;
EventBus bus = EventBus.getDefault();

public SocketClusterService() {
    super("SocketClusterService");
}
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "onCreate: socket:");
}

@Override
public void onDestroy() {
    super.onDestroy();
}

// Will be called asynchronously by Android
@Override
protected void onHandleIntent(Intent intent) {
    this.socket = new Socket(SERVER_URL + cobaltStore.getToken());
    socket.setListener(this);

    //This will set automatic-reconnection to server with delay of 2 seconds and repeating it for 30 times
    socket.setReconnection(new ReconnectStrategy().setDelay(2000).setMaxAttempts(30));
    socket.connect();

    channel = socket.createChannel("channelName");
    channel.subscribe((name, error, data) -> {
        Log.d(TAG, "onHandleIntent: name " + channel.getChannelName());
        Log.d(TAG, "onHandleIntent: error " + error);
        Log.d(TAG, "onHandleIntent: data " + data);
    });

    channel.onMessage((channelName, object) -> {
                 //use object data..!!
    });
}

@Subscribe
public void onEvent(CobaltStore.CobaltStoreChangeEvent event) {

    Log.e(TAG, "EVENT");

    if (channel != null) {
        channel.publish("We come in peace!");
    }
}

@Override
public void onConnected(Socket socket, Map<String, List<String>> headers) {
    Log.e(TAG, "onConnected");
    Log.d(TAG, "onConnected: " + headers);

}

@Override
public void onDisconnected(Socket socket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
    Log.e(TAG, "onDisconnected");
}

@Override
public void onConnectError(Socket socket, WebSocketException exception) {
    Log.e(TAG, "onConnectError ", exception);
}

@Override
public void onAuthentication(Socket socket, Boolean status) {
    Log.d(TAG, "onAuthentication: status " + status);
}

@Override
public void onSetAuthToken(String token, Socket socket) {  socket.setAuthToken(token);    }

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions