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.IO acknowledgement #33

Closed
wonderhero opened this issue Jul 4, 2013 · 15 comments
Closed

Socket.IO acknowledgement #33

wonderhero opened this issue Jul 4, 2013 · 15 comments

Comments

@wonderhero
Copy link

Hi,

I am looking for acknowledgment function for the socket io client, there are some socket event callback in my project need to get acknowledgement. Is this available?

Thanks.

@koush
Copy link
Owner

koush commented Jul 4, 2013

Coincidentally, very soon! I am in the process of refactoring the socket.io client to add that feature, as well as many others. Check out the "wip" branch.

Should be released this weekend.

@wonderhero
Copy link
Author

Cool.. Thanks alot.

@koush
Copy link
Owner

koush commented Jul 4, 2013

Fixed in the master branch. Will push to Maven soon.

Requiring an ack:

SocketIOClient client = SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://koush.clockworkmod.com:8080/", null).get();

client.emit("hello", new Acknowledge() {
    @Override
    public void acknowledge(JSONArray arguments) {

    }
});

Sending an ack:

SocketIOClient client = SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://koush.clockworkmod.com:8080/", null).get();

client.setStringCallback(new StringCallback() {
    @Override
    public void onString(String string, Acknowledge acknowledge) {
        assertNotNull(acknowledge);
        acknowledge.acknowledge(new JSONArray().put(string));
    }
});

@koush koush closed this as completed Jul 4, 2013
@g00fy-
Copy link

g00fy- commented Jul 14, 2013

Are you sure acknowledges pass correct arguments ?
In my case acknowledge gets invoked but the server doesn't receive acknowledge arguments (it says it's undefined)

@koush
Copy link
Owner

koush commented Jul 14, 2013

Let me double check. I'm fairly certain it does, as I have tests unit tests around it.

@koush koush reopened this Jul 14, 2013
@wonderhero
Copy link
Author

Hi, I have worked with the acknowledge call back.It does the job well as intented..

@koush
Copy link
Owner

koush commented Jul 15, 2013

@g00fy- if you could let me know which socket.io server and version you are on, i can take a look.

@g00fy-
Copy link

g00fy- commented Jul 15, 2013

I am using socket.io v9.11 (I have also tries 9.16), the server address is pxl.pl:8000

this is the server code :

  socket.on('ping', function(ping){
       var ack = function(data){
        socket.emit('ack',data);
       }
    socket.emit('pong','pong', ack);
  });

on the client - browser this code works:


socket = io.connect()
c {socket: d, name: "", flags: Object, json: d, ackPackets: 0…}
// XHR finished loading: "http://pxl.pl:8000/socket.io/1/?t=1373874186168". socket.io.min.js:2
socket.on('ack',function(x){console.log("ack",x)})
// c {socket: d, name: "", flags: Object, json: d, ackPackets: 0…}
socket.emit('ping');
//  c {socket: d, name: "", flags: Object, json: d, ackPackets: 0…}
socket.on('pong',function(pong,ack){ack('client');})
// c {socket: d, name: "", flags: Object, json: d, ackPackets: 0…}
socket.emit('ping');
// c {socket: d, name: "", flags: Object, json: d, ackPackets: 0…}
ack client

@koush
Copy link
Owner

koush commented Jul 16, 2013

@g00fy- Thanks, will take a look with that test code.

@g00fy-
Copy link

g00fy- commented Jul 17, 2013

@koush any news about this issue? I was using 1.1.4 jar. Maybe the format of the websocket message is invalid ?

@koush
Copy link
Owner

koush commented Jul 17, 2013

Haven't had a chance to look at this yet, I'll be free this weekend I think

@koush
Copy link
Owner

koush commented Jul 19, 2013

@g00fy- This should be fixed with:

3845a96

@koush
Copy link
Owner

koush commented Jul 19, 2013

Please verify so I can close this issue.

@g00fy-
Copy link

g00fy- commented Jul 19, 2013

@koush Works! Thanks!

@koush koush closed this as completed Jul 19, 2013
@whuhenrylee
Copy link

I have the same issue,

on the server,if I use socket to emit a command , the acknowledge on client is ok , if I use io.sockets to emit a command, the acknowledge on the client is null

server code:
io.sockets.emit(COMMAND_NAME,emitData,function(d){
console.log('callback from client',d);
});
does not work;

socket.emit('command',{"commandStr":"testhenry"},function(d){
console.log(d);
});
works well
client.on("command", new EventCallback() {
@OverRide
public void onEvent(JSONArray arguments, Acknowledge acknowledge) {
Log.i("command","args: "+ arguments.toString());

                                try {

                                    if(acknowledge != null) acknowledge.acknowledge(new JSONArray().put("test"));//?does not work

                                    msgIntent.putExtra("msg", arguments.getJSONObject(0).getString("commandStr"));
                                    sendBroadcast(msgIntent);
                                } catch (JSONException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                //context.sendBroadcast(arg0);

                            }
                        });

the acknowledge is null.

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