Spring实现Netty-TCP-client-server简单实例
增加gradle依赖
1 | // https://mvnrepository.com/artifact/io.netty/netty-all |
netty下server实现
NettyServer
包:netty.tcp.server
1 | import com.cec.ice.netty.tcp.serverChannel.NettyServerChannel; |
NettyServerChannel
包:netty.tcp.serverChannel
1 | import com.cec.ice.netty.tcp.serverHandler.NettyServerHandler; |
NettyServerHandler
包:netty.tcp.serverHandler
1 | import io.netty.buffer.ByteBuf; |
netty下client实现
NettyClient
包:netty.tcp.client
1 | import com.cec.ice.netty.tcp.clientChannel.NettyClientChannel; |
NettyClientChannel
包:netty.tcp.clientChannel
1 | import com.cec.ice.netty.tcp.clientHandler.NettyClientHandler; |
NettyClientHandler
包:netty.tcp.clientHandler
1 | import io.netty.buffer.ByteBuf; |
Run
先运行服务端
再运行客户端
服务端结果:
1 | server started successfully... |
客户端结果:
1 | connected server successfully! |