package com.goafanti.common.webSocket;


import org.apache.commons.lang3.ObjectUtils;
import org.java_websocket.WebSocket;
import org.java_websocket.enums.ReadyState;

import java.net.URI;
import java.net.URISyntaxException;



public enum WebClientEnum {

    CLIENT;

    private static MsgWebSocketClient socketClient = null;

    public static void initClient(MsgWebSocketClient client) {
        socketClient = client;
        if(socketClient!=null) {
            socketClient.connect();
            while (socketClient.getReadyState().equals(ReadyState.OPEN)){
                socketClient.send("测试websocket。。。");
            }

        }
        boolean flag = true;
        int i=1000;
        while(flag) {
            while (!socketClient.getReadyState().equals(ReadyState.OPEN)){

            }
            socketClient.send("测试websocket。。。"+(i--));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if(i == 0) {
                flag = false;
            }
        }
    }

}
