Netty几大核心组件
netty
封装IO和线程的框架,简化开发
Mina
JAVA BIO NIO AIO
input 和output 针对的是内存 (cpu)
比如文件读到内存是input (read) 内存写到磁盘是output(write);
socket input到内存 ,内存output到socket;
磁盘/socket -> 机器(OS)内存-> JMM(应用程序内存)
//BIO accept 线程
public class IoClient { public static void main(String[] args) throws Exception { Socket socket = new Socket("127.0.0.1", 8888); OutputStream os= socket.getOutputStream(); os.write("hello"); os.close(); socket.close(); } }
public class IoServer {
public static void main(String[] args) throws Exception {
ServerSocket serverSocket = new ServerSocket(8888);
while(true){
Socket socket = serverSocket.accept();
new Thread(()->{
OutputStream outputStream = null;
try {
InputStream is= socket.getInputStream();
byte[] buff = new byte[1024];
int len = is.read(buff)
while (len>0){
String s = new String(buff,0,len);
sout(s);
}
} catch (IOException e) {
e.printStackTrace();
}finally {
//close();
}
},"Thread-"+ UUID.randomUUID()).start();
}
}
}
AIO
Block Non-Block
Block
Non-Block
Sync ASync
读半包
粘包
拆包
channel decoder encoder
pipeline handler
bootstrap serverBootStrap
eventLoopGroup eventLoop
Future/promise