netty 开发的基本流程
![](https://i-blog.csdnimg.cn/blog_migrate/aa3c0db32aeadfcbe4c4ee3af9f7f1c2.png)
实现客户端、服务器端
实现思路
![](https://i-blog.csdnimg.cn/blog_migrate/660d9a672f6fae6304d372328eb9a707.png)
netty 依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>netty-serv</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<!-- 服务器客户端分为两个模块 -->
<modules>
<module>netty-tcp-serv</module>
<module>netty-tcp-client</module>
</modules>
<dependencies>
<!-- netty依赖 -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.50.Final</version>
</dependency>
</dependencies>
</project>
服务器代码实现
package org.skystep.tcpserv;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
public class