核心代码如下
AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(new DefaultAsyncHttpClientConfig.Builder()
.setConnectTimeout(60000)
.setRequestTimeout(60000)
.setKeepAlive(true)
.build());
注意websocket的地址主要重载ping和pong
WebSocket ws = asyncHttpClient.prepareGet(“ws://codeforest.cn/queue/join”)
.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(
new WebSocketListener() {
}).build()).get();
@Override
重载下面的方法
public void onPingFrame(byte[] payload) {
System.out.println(“PingFrame”);
ws.sendPingFrame(payload);
}
@Override
public void onPongFrame(byte[] payload) {
System.out.println("onPongFrame");
ws.sendPongFrame(payload);
}