本文档为个人博客文档系统的备份版本、作者:小游、作者博客:点击访问
直接使用开源库:https://github.com/koush/AndroidAsync
上面那个好像只能建立websocket服务。我们换一个吧。。
https://github.com/TakahikoKawasaki/nv-websocket-client
参考代码如下:
package com.xiaoyou.xblog.tools;
import android.util.Log;
import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFactory;
import com.neovisionaries.ws.client.WebSocketFrame;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* websocket管理类,用于管理websocket请求
* @author 小游
*/
public class WebSocketManage{
/**连接超时时间*/
private static final int DEFAULT_CONNECT_TIMEOUT=3000;
/**重连超时时间*/
private static final int DEFAULT_RECONNECT_TI