// Path: app/src/main/java/com/demo/amazing/net/action/Action.java
// public class Action {
// 
//     public static final int UNKNOWN_ACTION = -1;
// 
//     public static final int LINK_ACTION = 1;
// 
//     public static final int FAIL_ACTION = 2;
// 
//     public static final int VOTE_ACTION = 3;
// 
//     public static final int DESC_ACTION = 4;
// 
//     public int action;// 动作类型
// 
//     public String desc;
// 
//     public Action(int action) {
//         this.action = action;
//     }
// 
//     public Action(int action, String desc) {
//         this.action = action;
//         this.desc = desc;
//     }
// 
//     public static Action builder() {
//         return new Action(UNKNOWN_ACTION, null);
//     }
// }
// 
// Path: app/src/main/java/com/demo/amazing/util/LogUtil.java
// public class LogUtil {
// 
//     public static void e(String msg) {
//         Log.e("free", msg);
//     }
// 
//     public static void d(String tag, String msg) {
//         Log.e("free", msg);
//     }
// }


import android.support.annotation.NonNull;
import com.demo.amazing.net.action.Action;
import com.demo.amazing.util.LogUtil;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okio.ByteString;

    private void start() {
        mockWebServer = new MockWebServer();
        mockWebServer.enqueue(new MockResponse().withWebSocketUpgrade(new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                super.onOpen(webSocket, response);
                LogUtil.e("server onOpen");
            }

            @Override
            public void onMessage(WebSocket webSocket, String text) {
                super.onMessage(webSocket, text);
                LogUtil.e("server onMessage=" + text);
                webSocket.send(getText(text));
            }

            @Override
            public void onMessage(WebSocket webSocket, ByteString bytes) {
                super.onMessage(webSocket, bytes);
            }

            @Override
            public void onClosing(WebSocket webSocket, int code, String reason) {
                super.onClosing(webSocket, code, reason);
            }

            @Override
            public void onClosed(WebSocket webSocket, int code, String reason) {
                super.onClosed(webSocket, code, reason);
// Path: app/src/main/java/com/demo/amazing/net/action/Action.java
// public class Action {
// 
//     public static final int UNKNOWN_ACTION = -1;
// 
//     public static final int LINK_ACTION = 1;
// 
//     public static final int FAIL_ACTION = 2;
// 
//     public static final int VOTE_ACTION = 3;
// 
//     public static final int DESC_ACTION = 4;
// 
//     public int action;// 动作类型
// 
//     public String desc;
// 
//     public Action(int action) {
//         this.action = action;
//     }
// 
//     public Action(int action, String desc) {
//         this.action = action;
//         this.desc = desc;
//     }
// 
//     public static Action builder() {
//         return new Action(UNKNOWN_ACTION, null);
//     }
// }
// 
// Path: app/src/main/java/com/demo/amazing/util/LogUtil.java
// public class LogUtil {
// 
//     public static void e(String msg) {
//         Log.e("free", msg);
//     }
// 
//     public static void d(String tag, String msg) {
//         Log.e("free", msg);
//     }
// }


// Path: app/src/main/java/com/demo/amazing/net/server/Server.java
import android.support.annotation.NonNull;
import com.demo.amazing.net.action.Action;
import com.demo.amazing.util.LogUtil;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okio.ByteString;


    private void start() {
        mockWebServer = new MockWebServer();
        mockWebServer.enqueue(new MockResponse().withWebSocketUpgrade(new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                super.onOpen(webSocket, response);
                LogUtil.e("server onOpen");
            }

            @Override
            public void onMessage(WebSocket webSocket, String text) {
                super.onMessage(webSocket, text);
                LogUtil.e("server onMessage=" + text);
                webSocket.send(getText(text));
            }

            @Override
            public void onMessage(WebSocket webSocket, ByteString bytes) {
                super.onMessage(webSocket, bytes);
            }

            @Override
            public void onClosing(WebSocket webSocket, int code, String reason) {
                super.onClosing(webSocket, code, reason);
            }

            @Override
            public void onClosed(WebSocket webSocket, int code, String reason) {
                super.onClosed(webSocket, code, reason);
                LogUtil.e("server onClosed: code=" + code + " reason=" + reason);