【Netty 实战:如何实现文件服务器?】整体比较简单,exceptionCaught 为异常时的处理 。
channelActive() 为客户端连接时,服务端返回客户端的提示 。
channelRead0() 为服务端对于客户端的反馈,就是通过客户端输入的文件路径,返回文件内容 。
测试验证我们直接使用本地的 telnet
- 打开命令行
192:~ houbinbin$ telnet localhost 8889Trying ::1...Connected to localhost.Escape character is '^]'.HELLO: Type the path of the file to retrieve.- 输入文件路径
/Users/houbinbin/code/_github/netty-learn/netty-learn-four/src/main/java/com/github/houbb/netty/learn/four/file/FileServer.java反馈如下:就是把 FileServer.java 这个文件内容全部返回回来了 。
OK: 2387/* * Copyright (c) 2019. houbinbin Inc. * netty-learn All rights reserved. */package com.github.houbb.netty.learn.four.file;....... 内容省略/** * <p> </p> * * <pre> Created: 2019/9/21 11:49 PM </pre> * <pre> Project: netty-learn </pre> * * @author houbinbin */public class FileServer { public static void main(String[] args) { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); .... 内容省略 }}Connection closed by foreign host.推荐阅读
- netty 服务端启动流程源码详解
- Netty 实战:如何实现 HTTP 服务器?
- 如何实现几百台SIP终端实现自动化部署
- 如何在 Linux 终端查看图像
- 龙井怎么分辨好坏,如何分辨真正的炭焙型铁观音
- 如何让肱二头肌变小呢
- 绿茶要怎么样保存,绿茶如何保存
- 白琳工夫怎么泡,如何区分白琳工夫
- 保存茶叶关键2,黄山毛峰如何保存
- 母亲的意义是什么如何教育世人
