Netty简单介绍
摘自官网介绍:
Netty is a NIO client server framework which enables quick and easy
development of network applications such as protocol servers and
clients. It greatly simplifies and streamlines network programming
such as TCP and UDP socket server. ‘Quick and easy’ doesn’t mean that
a resulting application will suffer from a maintainability or a
performance issue. Netty has been designed carefully with the
experiences earned from the implementation of a lot of protocols such
as FTP, SMTP, HTTP, and various binary and text-based legacy
protocols. As a result, Netty has succeeded to find a way to achieve
ease of development, performance, stability, and flexibility without a
compromise.
翻译:
Netty 是一个 NIO 客户端服务器框架,它可以快速轻松地开发网络应用程序,例如协议服务器和客户端。 它极大地简化和精简了 TCP 和 UDP 套接字服务器等网络编程。
“快速而简单”并不意味着生成的应用程序会受到可维护性或性能问题的影响。 Netty 是根据从许多协议(例如 FTP、SMTP、HTTP 以及各种基于二进制和文本的遗留协议)的实现中获得的经验而精心设计的。 结果,Netty 成功地找到了一种方法,可以在不妥协的情况下实现易于开发、性能、稳定性和灵活性。
前期准备
maven引入io.netty
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.63.Final</version>
</dependency>
服务端代码
package com.netty;
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.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.