AndroidAsync :异步Socket,http(client+server),websocket和socket.io的Android类库

jopen 8年前

AndroidAsync是一个用于Android应用的异步Socket,http(client+server),websocket和socket.io的类库。基于NIO,没有线程。它使用java.nio来管理连接。因此,所有连接都在一个单一的线程管理,而不是每一个线程。 NIO是极其有效的。

创建web sockets:

AsyncHttpClient.getDefaultInstance().websocket(get, "my-protocol", new WebSocketConnectCallback() {      @Override      public void onCompleted(Exception ex, WebSocket webSocket) {          if (ex != null) {              ex.printStackTrace();              return;          }          webSocket.send("a string");          webSocket.send(new byte[10]);          webSocket.setStringCallback(new StringCallback() {              public void onStringAvailable(String s) {                  System.out.println("I got a string: " + s);              }          });          webSocket.setDataCallback(new DataCallback() {              public void onDataAvailable(ByteBufferList byteBufferList) {                  System.out.println("I got some bytes!");                  // note that this data has been read                  byteBufferList.clear();              }          });      }  });

项目主页:http://www.open-open.com/lib/view/home/1371461635921