首页>代码>SpringBoot使用AOP实现简单验证、日志记录、使用NettySocket转发数据>/CallSocketDemo/src/main/java/com/lyg/call/clienttest/MutilClient.java
package com.lyg.call.clienttest;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.BufferedReader;
import java.io.InputStreamReader;



public class MutilClient {
    public static void main(String[] args) throws Exception {
        EventLoopGroup eventExecutors = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(eventExecutors).channel(NioSocketChannel.class).
                    handler(new MutilClientInitializer());

            Channel channel = bootstrap.connect("localhost", 1001).sync().channel();
//            channelFuture.channel().closeFuture().sync();
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            //用户登陆
            String strReg = "{\"jkid\":\"zxzc\",\"zxgh\":\"1103\" }" + "\r\n";
            channel.writeAndFlush(strReg+"\r\n");

           String str1="{\"jkid\":\"ldtp\",\"zxgh\":\"1101\",\"ldhm\": \"13759521000\",\"ldsj\": \"2020-12-13 11:10:00\"}";
           channel.writeAndFlush(str1+"\r\n");

            String str2="{\"jkid\":\"ldtp\",\"zxgh\":\"1102\",\"ldhm\": \"13759521000\",\"ldsj\": \"2020-12-13 11:11:00\"}";
            channel.writeAndFlush(str2+"\r\n");


            channel.writeAndFlush(br.readLine()+"\r\n");
            for (; ; ) {

                channel.writeAndFlush(br.readLine()+"\r\n");
            }

        } finally {
            eventExecutors.shutdownGracefully();
        }
    }
}
最近下载更多
youwuzuichen  LV11 2023年2月11日
jackyliu  LV10 2022年10月27日
jaonsang  LV25 2021年6月26日
飞翔的面包片  LV13 2021年6月18日
徐万强  LV9 2021年6月2日
wxm4252  LV12 2021年5月4日
李先森  LV19 2020年12月15日
15521120753  LV2 2020年12月15日
最代码官方  LV168 2020年12月13日
最近浏览更多
xkh123 3月13日
暂无贡献等级
流水本无情  LV9 2024年3月13日
Uting  LV3 2023年2月21日
java605  LV2 2023年1月12日
shenmofeng11  LV1 2022年12月26日
暂无贡献等级
MVP_HC  LV3 2022年11月30日
youwuzuichen  LV11 2022年10月28日
jackyliu  LV10 2022年10月27日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友