NettyClient.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //package com.fdkk.sxz.netty;
  2. //
  3. //import io.netty.bootstrap.Bootstrap;
  4. //import io.netty.channel.ChannelFuture;
  5. //import io.netty.channel.ChannelOption;
  6. //import io.netty.channel.EventLoopGroup;
  7. //import io.netty.channel.nio.NioEventLoopGroup;
  8. //import io.netty.channel.socket.SocketChannel;
  9. //import io.netty.channel.socket.nio.NioSocketChannel;
  10. //import lombok.extern.slf4j.Slf4j;
  11. //import org.springframework.beans.factory.annotation.Value;
  12. //import org.springframework.stereotype.Component;
  13. //
  14. //import java.util.HashMap;
  15. //import java.util.Map;
  16. //
  17. ///**
  18. // * 接收自有项目消息,转发给监管平台
  19. // *
  20. // * @version V1.0
  21. // * @file: com.yjrj.presalehouse.client.NettyClient
  22. // * @description: 自定义业务处理handler
  23. // * @author: wanggd
  24. // * @date 2021-04-06
  25. // */
  26. //@Component
  27. //@Slf4j
  28. //public class NettyClient {
  29. //
  30. // @Value("${netty.port:8081}")
  31. // private int port;
  32. // @Value("${netty.host:127.0.0.1}")
  33. // private String host;
  34. //
  35. // public static Bootstrap bootstrap = null;
  36. // public static SocketChannel socketChannel = null;
  37. // public static ChannelFuture future = null;
  38. // public Map<String, Bootstrap> map = new HashMap<>();
  39. //
  40. // /**
  41. // * 向监管平台发送消息
  42. // *
  43. // * @param msg 接收到的自有项目传递过来的消息
  44. // * @return
  45. // * @throws InterruptedException
  46. // */
  47. // public String sendMessage(String msg) throws InterruptedException {
  48. // if (!map.containsKey(host)) {
  49. // NettyClient.log.info("\n\n\n\n\n\n-------------------------新建连接服务端:" + host + ":" + port + "---------------------------");
  50. // EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
  51. // NettyClient.bootstrap = new Bootstrap();
  52. // NettyClient.bootstrap.channel(NioSocketChannel.class);
  53. // NettyClient.bootstrap.group(eventLoopGroup);
  54. // NettyClient.bootstrap.remoteAddress(host, port);
  55. // // 设置超时时间
  56. // NettyClient.bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000);
  57. // map.put(host, NettyClient.bootstrap);
  58. // } else {
  59. // NettyClient.log.info("\n\n\n\n\n\n--------------------------已连接服务端:" + host + ":" + port + "-----------------------------");
  60. // NettyClient.bootstrap = map.get(host);
  61. // }
  62. // NettyChannelInitializer customerChannelInitializer = new NettyChannelInitializer(msg);
  63. // NettyClient.bootstrap.handler(customerChannelInitializer);
  64. //
  65. // NettyClient.future = NettyClient.bootstrap.connect(host, port).sync();
  66. // if (NettyClient.future.isSuccess()) {
  67. // NettyClient.socketChannel = (SocketChannel) NettyClient.future.channel();
  68. // NettyClient.log.info("远程服务器已经连接, 可以进行数据交换..");
  69. // }
  70. // return customerChannelInitializer.getResponse();
  71. // }
  72. //}