Naoyuki Kanezawa 5ec5089231 tweak
2014-02-02 22:48:06 +09:00
2014-02-02 22:42:17 +09:00
2013-04-22 03:37:28 +09:00
2013-06-08 12:02:23 +09:00
2013-04-22 22:45:50 +09:00
2014-02-02 22:48:06 +09:00

Engine.IO-client.java

Build Status

This is the Engine.IO Client Library for Java, which is simply ported from the JavaScript client.

See also: Socket.IO-client.java

Installation

The latest artifact is available on Maven Central. Add the following dependency to your pom.xml.

<dependencies>
  <dependency>
    <groupId>com.github.nkzawa</groupId>
    <artifactId>engine.io-client</artifactId>
    <version>0.1.2</version>
  </dependency>
</dependencies>

Usage

Engine.IO-client.java has the similar api with the JS client. You can use Socket to connect:

socket = new Socket("ws://localhost") {
  @Override
  public void onopen() {
    socket.send("hi");
    socket.close();
  }

  @Override
  public void onmessage(String data) {}

  @Override
  public void onclose() {}

  @Override
  public void onerror(Exception err) {}
};
socket.open();

You can receive events as follows:

socket.on(Socket.EVENT_ERROR, new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    Exception err = (Exception)args[0];
  }
});

How to set options:

opts = new Socket.Options();
opts.transports = new String[] {WebSocket.NAME};

socket = new Socket("ws://localhost", opts) { ... };

Extra features only for Java client

Some features are added for simulating browser behavior like handling cookies.

socket.on(Socket.EVENT_TRANSPORT, new Emitter.listener() {
  @Override
  public void call(Object... args) {
    // Called on a new transport created.
    Transport transport = (Transport)args[0];

    transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
      @Override
      public void call(Object... args) {
        @SuppressWarnings("unchecked")
        Map<String, String> headers = (Map<String, String>)args[0];
        // send cookies to server.
        headers.put("Cookie", "foo=1;");
      }
    }).on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() {
      @Override
      public void call(Object... args) {
        @SuppressWarnings("unchecked")
        Map<String, String> headers = (Map<String, String>)args[0];
        // get cookies from server.
        String cookie = headers.get("Set-Cookie"));
      }
    });
  }
});

See the Javadoc for more details.

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

Features

This library supports all of the features the JS client does, including events, options and upgraging transport. Android is fully supported.

License

MIT

Description
Engine.IO Client Library for Java
Readme MIT 632 KiB
Languages
Java 99.1%
JavaScript 0.8%
Makefile 0.1%