vince
2024-01-17 d1e65a28fc73b543b8f34fe118712573682ff2fc
src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java
@@ -16,7 +16,7 @@
import java.util.Map;
/**
 * 通讯协议
 * 游仙主库,通讯协议
 */
@Slf4j
public class ClientEngine implements Runnable {
@@ -29,7 +29,7 @@
    private String host;
    private int port;
    private Channel defaultChannel;
    public static Channel defaultChannel;
    public ClientEngine(String host, int port) {
@@ -45,6 +45,7 @@
    @Override
    public void run() {
        try {
            startClient();
        } catch (Exception e) {
            e.printStackTrace();
@@ -52,7 +53,10 @@
    }
    public void startClient() throws Exception {
        if(defaultChannel != null){
            log.info("-----IP={},连接存在,直接使用",host);
            return;
        }
        EventLoopGroup group = new OioEventLoopGroup();
        Bootstrap b = new Bootstrap();
        //默认长连接
@@ -107,11 +111,11 @@
    }
    public Channel getChannel() {
    public static Channel getChannel() {
        return defaultChannel;
    }
    public static void add2ChannelMap(String key, Channel channel) {
    public  void add2ChannelMap(String key, Channel channel) {
        clientChannelMap.put(key, channel);
    }
@@ -128,6 +132,7 @@
            return channel;
        } else {
            channel.close();
            defaultChannel = null;
        }
        return null;
    }