Files
socket.io-client-java/README.md
2013-05-08 23:24:42 +09:00

1.3 KiB

Socket.IO-client.java

Build Status

This is the Socket.IO v1.0 Client Library for Java, which is simply ported from the JS client.

See also: https://github.com/nkzawa/engine.io-client.java

Usage

Socket.IO-client.java has almost the same api and features with the original JS client. You use IO#socket to initialize Socket:

socket = IO.socket("http://localhost");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

  @Override
  public void call(Object... objects) {
    socket.emit("foo", "hi");
    socket.disconnect();
  }

}).on("event", new Emitter.Listener() {

  @Override
  public void call(Object... objects) {}

}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

  @Override
  public void call(Object... objects) {}

});
socket.connect();

Options are supplied as follow:

IO.Options opts = new IO.Options();
opts.forceNew = true;

socket = IO.socket("http://localhost", opts);

You can get a callback with the Ack:

socket.emit("foo", "woot", new Ack() {
  @Override
  public void call(Object... args) {}
});

See the Javadoc for more details.

http://nkzawa.github.io/socket.io-client.java/apidocs/

License

MIT