commit 2c1e62b911db294e6428715f0419fa60f34cc778 Author: 朱毅骏 Date: Sat Oct 9 09:02:12 2021 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..082f479 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Created by .ignore support plugin (hsz.mobi) +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen +.idea/ +target/ diff --git a/2.txt b/2.txt new file mode 100644 index 0000000..7a1a77d --- /dev/null +++ b/2.txt @@ -0,0 +1,9 @@ + +B-> SYN -> A +B-> SYN/ACK ->A +B <-ACK<- A +Ĵη +B-> ACK/FIN -> A +B<- ACK <- A +B<- ACK/FIN <- A +B-> ACK -> A diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..738768d Binary files /dev/null and b/logo.png differ diff --git a/logo2.png b/logo2.png new file mode 100644 index 0000000..738768d Binary files /dev/null and b/logo2.png differ diff --git a/nettyPro/.gitignore b/nettyPro/.gitignore new file mode 100644 index 0000000..082f479 --- /dev/null +++ b/nettyPro/.gitignore @@ -0,0 +1,11 @@ +# Created by .ignore support plugin (hsz.mobi) +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen +.idea/ +target/ diff --git a/nettyPro/pom.xml b/nettyPro/pom.xml new file mode 100644 index 0000000..43bbb27 --- /dev/null +++ b/nettyPro/pom.xml @@ -0,0 +1,19 @@ + + + + netty_ALL + cn.zyjblogs.netty + 1.0 + + 4.0.0 + + nettyPro + + + 8 + 8 + + + \ No newline at end of file diff --git a/nettyPro/src/main/java/cn/zyjblogs/netty/bio/BIOServer.java b/nettyPro/src/main/java/cn/zyjblogs/netty/bio/BIOServer.java new file mode 100644 index 0000000..31741ad --- /dev/null +++ b/nettyPro/src/main/java/cn/zyjblogs/netty/bio/BIOServer.java @@ -0,0 +1,59 @@ +package cn.zyjblogs.netty.bio; + +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class BIOServer { + public static void main(String[] args) { + + //线程池机制 + + //思路 + //1. 创建一个线程池 + //2. 如果有客户端链接,就创建一个线程与之通讯 + ExecutorService newCachedThreadPool = Executors.newCachedThreadPool(); + + //创建ServerSocket + try { + ServerSocket serverSocket = new ServerSocket(6666); + System.out.println("服务器启动了"); + while (true) { + System.out.println("等待连接"); + final Socket socket = serverSocket.accept(); + System.out.println("连接到一个客户端了"); + //就创建一个线程与之通讯 + newCachedThreadPool.execute(() -> { + //可以和客户端通讯 + handler(socket); + }); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void handler(Socket socket) { + try (InputStream inputStream = socket.getInputStream()) { + System.out.println("线程信息id = "+Thread.currentThread().getId()+" 名称 = "+Thread.currentThread().getId()); + byte[] bytes = new byte[1024]; + while (true) { + System.out.println("read...."); + int read = inputStream.read(bytes); + System.out.println("线程信息id = "+Thread.currentThread().getId()+" 名称 = "+Thread.currentThread().getId()); + if (read == -1) { + break; + } + //输出客户端发送的数据 + System.out.println(new String(bytes,0,read)); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + System.out.println("关闭客户端链接"); + } + } +} diff --git a/nettyPro/src/main/java/cn/zyjblogs/netty/nio/BasicBuffer.java b/nettyPro/src/main/java/cn/zyjblogs/netty/nio/BasicBuffer.java new file mode 100644 index 0000000..26f762a --- /dev/null +++ b/nettyPro/src/main/java/cn/zyjblogs/netty/nio/BasicBuffer.java @@ -0,0 +1,23 @@ +package cn.zyjblogs.netty.nio; + +import java.nio.IntBuffer; + +public class BasicBuffer { + public static void main(String[] args) { + //创建一个buffer + IntBuffer intBuffer = IntBuffer.allocate(5); + //向buffer中存入数据 + for (int i=0;i