Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Can't get emit respond #116

Open
anormobile opened this issue Feb 4, 2015 · 1 comment
Open

Can't get emit respond #116

anormobile opened this issue Feb 4, 2015 · 1 comment

Comments

@anormobile
Copy link

If somebody can show me, what's wrong with my code?
I really spend a lot of time in attempt to figure out this issue.
The "chatinfo" event is passing automatically, after success connect to the server.

    private void getList(SocketIO socket) {
        try {
            socket.emit(EventList.GETLIST, new JSONObject().put("sortByDate", true));
            Log.v("getList", "Emit was sent!!!<<<<<<<<<<<<<<<<<<");
        } catch (JSONException e) {
            e.printStackTrace();
            Log.v("getList", "Emit was !!!!!!!!!!!!NOT!!!!!!!!!!!!!!! sent!!!<<<<<<<<<<<<<<<<<<");
        }
    } 
    @Override
    public void on(String s, IOAcknowledge ioAcknowledge, Object... objects) {
        JSONObject respond = (JSONObject) objects[0];
        Log.d("testFromOn", "String s = " + s);
        Log.d("testFromOn", "on" + respond);
        switch (s) {
            case GETLIST:
                Log.d("GETLIST", "GETLIST responce: " + s);
                break;
I/io.socket﹕ < 1::
D/test﹕ onConnect
I/io.socket﹕ < 5:::{"name":"chatinfo","args":[{"onlineCount":0,"onlineFriendsCount":0,"unreadCount":7,"unreadFriendsCount":0,"userInfo":{"avatar":"1415903272343.jpg","url":"/user/5431b4955518085d5db4be23","_id":"5431b4955518085d5db4be23"}}]}
D/testFromOn﹕ String s = chatinfo
D/testFromOn﹕ on{"onlineCount":0,"onlineFriendsCount":0,"unreadCount":7,"unreadFriendsCount":0,"userInfo":{"avatar":"1415903272343.jpg","url":"\/user\/5431b4955518085d5db4be23","_id":"5431b4955518085d5db4be23"}}
I/io.socket﹕ > 5:::{"name":"getlist","args":[{"sortByDate":true}]}
V/getList﹕ Emit was sent!!!<<<<<<<<<<<<<<<<<<
I/io.socket﹕ > 2::
I/io.socket﹕ > 5:::{"name":"getlist","args":[{"sortByDate":true}]}
V/getList﹕ Emit was sent!!!<<<<<<<<<<<<<<<<<<
I/io.socket﹕ < 2::
I/io.socket﹕ > 2::
@anormobile
Copy link
Author

Finally my problem was not so really problem. I just miss to add one more parameter to my emit. So nobody catch the server's respond.

The only one thing was to add:

IOAcknowledge ack = new IOAcknowledge() {
@Override
public void ack(Object... args) {
    if (args.length > 0) {
        Log.d("SocketIO", "" + args[0]);
    }
}
}

And pass the IOAcknowledge to the emit method:

socket.emit(EventList.GETLIST, ack, new JSONObject().put("sortByDate", true));

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

No branches or pull requests

1 participant