Giter Club home page Giter Club logo

Comments (15)

koush avatar koush commented on August 28, 2024

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.

from androidasync.

wonderhero avatar wonderhero commented on August 28, 2024

Cool.. Thanks alot.

from androidasync.

koush avatar koush commented on August 28, 2024

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

from androidasync.

g00fy- avatar g00fy- commented on August 28, 2024

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)

from androidasync.

koush avatar koush commented on August 28, 2024

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

from androidasync.

wonderhero avatar wonderhero commented on August 28, 2024

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

from androidasync.

koush avatar koush commented on August 28, 2024

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

from androidasync.

g00fy- avatar g00fy- commented on August 28, 2024

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

from androidasync.

koush avatar koush commented on August 28, 2024

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

from androidasync.

g00fy- avatar g00fy- commented on August 28, 2024

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

from androidasync.

koush avatar koush commented on August 28, 2024

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

from androidasync.

koush avatar koush commented on August 28, 2024

@g00fy- This should be fixed with:

3845a96

from androidasync.

koush avatar koush commented on August 28, 2024

Please verify so I can close this issue.

from androidasync.

g00fy- avatar g00fy- commented on August 28, 2024

@koush Works! Thanks!

from androidasync.

whuhenrylee avatar whuhenrylee commented on August 28, 2024

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.

from androidasync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.