aibo

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

创建web sockets:

 

01 AsyncHttpClient.getDefaultInstance().websocket(get, "my-protocol", new WebSocketConnectCallback() {
02     @Override
03     public void onCompleted(Exception ex, WebSocket webSocket) {
04         if (ex != null) {
05             ex.printStackTrace();
06             return;
07         }
08         webSocket.send("a string");
09         webSocket.send(new byte[10]);
10         webSocket.setStringCallback(new StringCallback() {
11             public void onStringAvailable(String s) {
12                 System.out.println("I got a string: " + s);
13             }
14         });
15         webSocket.setDataCallback(new DataCallback() {
16             public void onDataAvailable(ByteBufferList byteBufferList) {
17                 System.out.println("I got some bytes!");
18                 // note that this data has been read
19                 byteBufferList.clear();
20             }
21         });
22     }
23 });

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

分类:

技术点:

相关文章:

  • 2021-09-25
  • 2021-06-10
  • 2021-10-15
  • 2021-08-06
  • 2022-02-17
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
猜你喜欢
  • 2022-02-02
  • 2021-11-04
  • 2022-12-23
  • 2021-10-02
  • 2021-06-23
  • 2021-07-03
相关资源
相似解决方案