Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aalap03 opened this issue Oct 22, 2018 · 12 comments
Open

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

aalap03 opened this issue Oct 22, 2018 · 12 comments

Comments

@aalap03
Copy link

aalap03 commented Oct 22, 2018

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);    }

}

@sacOO7
Copy link
Owner

sacOO7 commented Nov 3, 2018

Hi @aalap03 , can you provide your exact problem? I need little more description... It will be helpful if you can provide me with little description about where exactly it get stuck.

@aalap03
Copy link
Author

aalap03 commented Nov 5, 2018

I subscribe to the server channel to receive updates and I receive messages in onMessage method.

I use 3 Test phones for development purpose, The Issue is on one of my test phones (Galaxy S7 Edge API 26), I don't receive Socket Updates. The phones in which it works is another Galaxy s7Edge with API 26 and Galaxy s5 NEO API 24.

I checked the not working phone's notification settings and all looks fine. I am not able to figure out what can be the issue here.

@sacOO7
Copy link
Owner

sacOO7 commented Nov 12, 2018

sorry @aalap03 , I am still looking into the issue. I am planning to use OkHTTP websockets instead of current websocket library.... Will push the code till end of this week.

@SanderVeer
Copy link

@sacOO7 Can you give us some more info on your estimated timeline for the OkHTTP socket integration? It's something we're definitely looking forward to to use in our app

@sacOO7
Copy link
Owner

sacOO7 commented Nov 21, 2018

Hi @aalap03 @SanderGemoro expect update from me on this till tomorrow 👍

@aalap03
Copy link
Author

aalap03 commented Nov 22, 2018

ok. Will wait for it eagerly.

@sacOO7
Copy link
Owner

sacOO7 commented Dec 4, 2018

Hi @aalap03 , I have created branch for the same here https://github.com/sacOO7/socketcluster-client-java/tree/feature/okHTTP. Sorry for the delay. It was more work than expected. I will release unofficial version of the library so that you can test it on your phones asap.

@sacOO7
Copy link
Owner

sacOO7 commented Dec 4, 2018

Hi @aalap03 @SanderGemoro I have published beta version related to above code. You can include it in your code by using

compile 'io.github.sac:SocketclusterClientJava:2.0.0-beta'

There are some method signatures which got changed due to change in library. But, you should be able to fix it without any problem. Please let me know if you face any problems with this latest release.

@yasirtahir
Copy link

I'm facing the same issue. The socket is working fine on Emulator but it's not working on real device. Can someone please comment if the issue is fixed?

@sacOO7
Copy link
Owner

sacOO7 commented Apr 22, 2020 via email

@yasirtahir
Copy link

I'm testing the latest implementation on Emulator and it's working fine. But when I'm sending the complied APK to testing team, the socket updates aren't coming. Unfortunately, I don't have any real device with me at the moment to inspect the issue in detail with logs.

@sacOO7
Copy link
Owner

sacOO7 commented Apr 22, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants