- package top.dsbbs2.nt;
- import io.netty.bootstrap.ServerBootstrap;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.*;
- import io.netty.channel.nio.NioEventLoopGroup;
- import io.netty.channel.socket.nio.NioServerSocketChannel;
- import io.netty.handler.codec.string.StringDecoder;
- import io.netty.handler.codec.string.StringEncoder;
- import io.netty.util.AttributeKey;
- import java.nio.charset.StandardCharsets;
- import java.util.Timer;
- import java.util.TimerTask;
- public class ServerMain {
- {
- ServerBootstrap b=new ServerBootstrap();
- b.group(new NioEventLoopGroup(8),new NioEventLoopGroup(8));
- b.childOption(ChannelOption.TCP_NODELAY,true);
- b.channel(NioServerSocketChannel.class);
- b.childHandler(new ChannelInitializer<Channel>() {
- @Override
- ch.pipeline().addLast(new StringEncoder());
- ch.pipeline().addLast(new StringDecoder());
- ch.pipeline().addLast(new ChannelInboundHandlerAdapter(){
- @Override
- @Override
- public void run() {
- if(!ctx.channel().isActive())
- return;
- ctx.channel().writeAndFlush("k5RTD6n3zfiCww2dKBhkfvhkPlH4flkxuHfxTUT6GQxRxBmevKcyGFMGbdOr6olJDYczc0lAbUhtQbODc7ecoTg17tXS6Rs6AtgL1ZwhhXPjpC6K0T3ssjP7zeTNdo3lDwJHkX7yIzYRJsSJOQi32ypOHkdB0hqVITJB4JmpO9e6IMIZDmzcLtrW3VhxfgURzmlD3DML0NMVC3XewQbwAMhqUN6dNKdMxbfF4kC4D8BjEDrT4I668M8jutZLolrJdZXABxhFILI24BBKOysql5FfaJTOXP7ay9tSY5BYPyCQKslEPy3EbCNjs2m5evnCwEhFCMO7qoAcfyGx63tN4RkDsvCKhzVcnZAX6VWUHV5ba7syDXxrQYgqqjXHn0gSnR1NSzCnpH02oh5XQX5d9altnHdhm1xLJAgsq97vr7IM1kw203qYDFbeKzmh3bln45G5JYadEuttltV9RdyiSfx7mx81KQJDAKtO5PvzEUl7UndYAFQ2zw1Y4xY95qGu"+"\r\n");
- }
- }, 0, 1);
- super.channelActive(ctx);
- }
- });
- }
- });
- b.bind(2333);
- }
- }
- package top.dsbbs2.nt;
- import io.netty.bootstrap.Bootstrap;
- import io.netty.channel.*;
- import io.netty.channel.nio.NioEventLoopGroup;
- import io.netty.channel.socket.nio.NioSocketChannel;
- import io.netty.handler.codec.string.StringDecoder;
- import io.netty.handler.codec.string.StringEncoder;
- public class ClientMain {
- {
- Bootstrap b=new Bootstrap();
- b.group(new NioEventLoopGroup(8));
- b.option(ChannelOption.TCP_NODELAY,true);
- b.channel(NioSocketChannel.class);
- b.handler(new ChannelInitializer<Channel>() {
- @Override
- ch.pipeline().addLast(new StringEncoder());
- ch.pipeline().addLast(new StringDecoder());
- ch.pipeline().addLast(new ChannelInboundHandlerAdapter(){
- @Override
- super.channelRead(ctx, msg);
- }
- });
- }
- });
- b.connect("127.0.0.1",2333);
- }
- }
t
Posted by Anonymous on Sat 15th Oct 2022 03:39
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.