//package com.fdkk.sxz.netty; // //import io.netty.bootstrap.Bootstrap; //import io.netty.channel.ChannelFuture; //import io.netty.channel.ChannelOption; //import io.netty.channel.EventLoopGroup; //import io.netty.channel.nio.NioEventLoopGroup; //import io.netty.channel.socket.SocketChannel; //import io.netty.channel.socket.nio.NioSocketChannel; //import lombok.extern.slf4j.Slf4j; //import org.springframework.beans.factory.annotation.Value; //import org.springframework.stereotype.Component; // //import java.util.HashMap; //import java.util.Map; // ///** // * 接收自有项目消息,转发给监管平台 // * // * @version V1.0 // * @file: com.yjrj.presalehouse.client.NettyClient // * @description: 自定义业务处理handler // * @author: wanggd // * @date 2021-04-06 // */ //@Component //@Slf4j //public class NettyClient { // // @Value("${netty.port:8081}") // private int port; // @Value("${netty.host:127.0.0.1}") // private String host; // // public static Bootstrap bootstrap = null; // public static SocketChannel socketChannel = null; // public static ChannelFuture future = null; // public Map map = new HashMap<>(); // // /** // * 向监管平台发送消息 // * // * @param msg 接收到的自有项目传递过来的消息 // * @return // * @throws InterruptedException // */ // public String sendMessage(String msg) throws InterruptedException { // if (!map.containsKey(host)) { // NettyClient.log.info("\n\n\n\n\n\n-------------------------新建连接服务端:" + host + ":" + port + "---------------------------"); // EventLoopGroup eventLoopGroup = new NioEventLoopGroup(); // NettyClient.bootstrap = new Bootstrap(); // NettyClient.bootstrap.channel(NioSocketChannel.class); // NettyClient.bootstrap.group(eventLoopGroup); // NettyClient.bootstrap.remoteAddress(host, port); // // 设置超时时间 // NettyClient.bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000); // map.put(host, NettyClient.bootstrap); // } else { // NettyClient.log.info("\n\n\n\n\n\n--------------------------已连接服务端:" + host + ":" + port + "-----------------------------"); // NettyClient.bootstrap = map.get(host); // } // NettyChannelInitializer customerChannelInitializer = new NettyChannelInitializer(msg); // NettyClient.bootstrap.handler(customerChannelInitializer); // // NettyClient.future = NettyClient.bootstrap.connect(host, port).sync(); // if (NettyClient.future.isSuccess()) { // NettyClient.socketChannel = (SocketChannel) NettyClient.future.channel(); // NettyClient.log.info("远程服务器已经连接, 可以进行数据交换.."); // } // return customerChannelInitializer.getResponse(); // } //}