From efb5bd5c5fbfe36829a2fcf3fb4d1adebcbf772d Mon Sep 17 00:00:00 2001 From: javazyk2021 Date: Thu, 25 Jan 2024 21:43:35 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feature:init=20hello=20world=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 51 ++++++++++++------- .idea/.gitignore | 8 +++ .idea/encodings.xml | 11 ++++ .idea/misc.xml | 15 ++++++ .idea/vcs.xml | 6 +++ netty-client/pom.xml | 26 ++++++++++ .../java/tool/zyk/hello/NettyHelloClient.java | 35 +++++++++++++ netty-server/pom.xml | 34 +++++++++++++ .../java/tool/zyk/hello/NettyHelloServer.java | 40 +++++++++++++++ pom.xml | 43 ++++++++++++++++ 10 files changed, 251 insertions(+), 18 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 netty-client/pom.xml create mode 100644 netty-client/src/main/java/tool/zyk/hello/NettyHelloClient.java create mode 100644 netty-server/pom.xml create mode 100644 netty-server/src/main/java/tool/zyk/hello/NettyHelloServer.java create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore index a1c2a23..5ff6309 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,38 @@ -# Compiled class file -*.class +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Log file -*.log +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr -# BlueJ files -*.ctxt +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar +### VS Code ### +.vscode/ -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..1df2401 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cc10980 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/netty-client/pom.xml b/netty-client/pom.xml new file mode 100644 index 0000000..b23916e --- /dev/null +++ b/netty-client/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + tool.zyk + netty-learn + 1.0-SNAPSHOT + + + netty-client + + + 8 + 8 + UTF-8 + + + + + io.netty + netty-all + + + \ No newline at end of file diff --git a/netty-client/src/main/java/tool/zyk/hello/NettyHelloClient.java b/netty-client/src/main/java/tool/zyk/hello/NettyHelloClient.java new file mode 100644 index 0000000..18318b8 --- /dev/null +++ b/netty-client/src/main/java/tool/zyk/hello/NettyHelloClient.java @@ -0,0 +1,35 @@ +package tool.zyk.hello; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.string.StringEncoder; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * author: zyk + * datetime: 2024/1/25 21:32 + * describe: + */ +public class NettyHelloClient { + public static void main(String[] args) throws InterruptedException { + new Bootstrap() + .group(new NioEventLoopGroup()) + .channel(NioSocketChannel.class) + .handler(new ChannelInitializer() { + @Override + protected void initChannel(Channel channel) throws Exception { + channel.pipeline().addLast(new StringEncoder()); + } + }) + .connect("127.0.0.1", 8080) + .sync() + .channel() + .writeAndFlush("helloWorld"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + } +} diff --git a/netty-server/pom.xml b/netty-server/pom.xml new file mode 100644 index 0000000..7cd5402 --- /dev/null +++ b/netty-server/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + tool.zyk + netty-learn + 1.0-SNAPSHOT + + + netty-server + + + 8 + 8 + UTF-8 + + + + + io.netty + netty-all + + + org.springframework.boot + spring-boot-starter-logging + + + org.projectlombok + lombok + + + \ No newline at end of file diff --git a/netty-server/src/main/java/tool/zyk/hello/NettyHelloServer.java b/netty-server/src/main/java/tool/zyk/hello/NettyHelloServer.java new file mode 100644 index 0000000..614ec6d --- /dev/null +++ b/netty-server/src/main/java/tool/zyk/hello/NettyHelloServer.java @@ -0,0 +1,40 @@ +package tool.zyk.hello; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.string.StringDecoder; +import lombok.extern.slf4j.Slf4j; + +/** + * author: zyk + * datetime: 2024/1/25 21:24 + * describe: + */ +@Slf4j +public class NettyHelloServer { + public static void main(String[] args) { + new ServerBootstrap() + .group(new NioEventLoopGroup()) + .channel(NioServerSocketChannel.class) + .childHandler(new ChannelInitializer() { + @Override + protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { + nioSocketChannel.pipeline().addLast(new StringDecoder()); + nioSocketChannel.pipeline().addLast(new SimpleChannelInboundHandler() { + @Override + protected void channelRead0(ChannelHandlerContext channelHandlerContext, String s) throws Exception { + log.info("服务器获取信息了:{}", s); + + } + }); + } + }) + .bind(8080); + + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..82098ec --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + tool.zyk + netty-learn + 1.0-SNAPSHOT + pom + + org.springframework.boot + spring-boot-starter-parent + 2.3.3.RELEASE + + + netty-client + netty-server + + + + 8 + 8 + UTF-8 + 4.1.39.Final + 1.18.30 + + + + + io.netty + netty-all + ${netty-all.version} + + + org.projectlombok + lombok + ${lombok.version} + + + + + \ No newline at end of file -- Gitee From 5e3cb1c6a3e82c946b2a85f25b6aa54d0bfdfd0c Mon Sep 17 00:00:00 2001 From: ZhangYongkang Date: Thu, 25 Jan 2024 13:18:22 +0000 Subject: [PATCH 2/5] Initial commit --- .gitignore | 51 ++++++++++++++------------------------- .idea/git_toolbox_prj.xml | 15 ++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 .idea/git_toolbox_prj.xml diff --git a/.gitignore b/.gitignore index 5ff6309..a1c2a23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,23 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ +# Compiled class file +*.class -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr +# Log file +*.log -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache +# BlueJ files +*.ctxt -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ +# Mobile Tools for Java (J2ME) +.mtj.tmp/ -### VS Code ### -.vscode/ +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar -### Mac OS ### -.DS_Store \ No newline at end of file +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..02b915b --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file -- Gitee From 9aa1da7cba2c4c4a36e1e358dd115641752189fe Mon Sep 17 00:00:00 2001 From: javazyk2021 Date: Thu, 25 Jan 2024 21:43:35 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feature:init=20hello=20world=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index a1c2a23..5ff6309 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,38 @@ -# Compiled class file -*.class +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Log file -*.log +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr -# BlueJ files -*.ctxt +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar +### VS Code ### +.vscode/ -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +### Mac OS ### +.DS_Store \ No newline at end of file -- Gitee From 5a857eb44ef98e4ea7e5f378023843e69863510a Mon Sep 17 00:00:00 2001 From: javazyk2021 Date: Thu, 25 Jan 2024 21:59:17 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feature:init=20hello=20world=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 5ff6309..a1c2a23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,23 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ +# Compiled class file +*.class -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr +# Log file +*.log -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache +# BlueJ files +*.ctxt -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ +# Mobile Tools for Java (J2ME) +.mtj.tmp/ -### VS Code ### -.vscode/ +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar -### Mac OS ### -.DS_Store \ No newline at end of file +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* -- Gitee From 20270aeed2442bdac7a625e78d63fc1d62458ffe Mon Sep 17 00:00:00 2001 From: javazyk2021 Date: Thu, 25 Jan 2024 22:03:43 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feature:init=20hello=20world=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 21 +++++ .idea/jarRepositories.xml | 20 +++++ .idea/workspace.xml | 181 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..32725b1 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..c364a09 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..f8da396 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1706188747019 + + + + + + + + + + \ No newline at end of file -- Gitee