Telnet
来源:互联网 发布:jquery书籍推荐知乎 编辑:程序博客网 时间:2024/06/05 14:07
首先说明一下前提:
① 安装了Telnet客户端(服务器);② 本机防火墙开启了8080端口(入站规则);
后台使用的netty,会将Telnet发送的数据打印到控制台。
这里主要说明如何使用Telnet发送数据。
① cmd 进入dos
② 连接ip 端口
telnet localhost 8080
③ ctrl+]回显内容
④ 回车,进入编辑状态
⑤ 输入内容
后台支持
服务端:
package com.netty.discard;import io.netty.bootstrap.ServerBootstrap;import io.netty.channel.ChannelFuture;import io.netty.channel.ChannelInitializer;import io.netty.channel.ChannelOption;import io.netty.channel.EventLoopGroup;import io.netty.channel.nio.NioEventLoopGroup;import io.netty.channel.socket.SocketChannel;import io.netty.channel.socket.nio.NioServerSocketChannel;/*** 丢弃任何进入的数据*/public class DiscardServer { private int port; public DiscardServer(int port) { this.port = port; } public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); // (1) EventLoopGroup workerGroup = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); // (2) try { b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class); // (3) b.childHandler(new ChannelInitializer<SocketChannel>(){ // (4) @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new DiscardServerHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); // (6) // 绑定端口,开始接收进来的连接 ChannelFuture f = b.bind(port).sync(); // (7) // 等待服务器 socket 关闭 。 // 在这个例子中,这不会发生,但你可以优雅地关闭你的服务器。 f.channel().closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } } public static void main(String[] args) throws Exception { int port; if (args.length > 0) { port = Integer.parseInt(args[0]); } else { port = 8080; } new DiscardServer(port).run(); }}
处理器:
package com.netty.discard;import io.netty.buffer.ByteBuf;import io.netty.channel.ChannelHandlerContext;import io.netty.channel.ChannelInboundHandlerAdapter;import io.netty.util.ReferenceCountUtil;/*** 处理服务端 channel.*/public class DiscardServerHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { // (2) // 默默地丢弃收到的数据// ((ByteBuf) msg).release(); // (3) ByteBuf in = (ByteBuf) msg; try { while(in.isReadable()){ System.out.print((char)in.readByte()); System.out.flush(); } }finally{ ReferenceCountUtil.release(msg); // (2) } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // (4) // 当出现异常就关闭连接 cause.printStackTrace(); ctx.close(); }}
阅读全文
0 0
- telnet
- Telnet
- telnet
- Telnet
- telnet
- telnet
- telnet
- Telnet
- telnet
- telnet
- telnet
- telnet
- telnet
- telnet
- telnet
- telnet
- telnet
- telnet
- 正则表达式连续匹配多个字符
- VIDEO INPAINTING OF COMPLEX SCENES
- Windows下常用的100个CMD指令以及常见的操作
- Codeforces Round #446 (Div. 2) D. Gluttony 构造 置换
- Java实现:两个乒乓球队进行比赛问题
- Telnet
- var和let在异步任务队列中的执行差异
- OAuth2.0认证和授权机制讲解
- JAVA Head First 第五章 编写程序
- 不要错过:高级UI至高境界之封装自己的动画框架
- 阿里Linux服务器部署 关闭防火墙tomcat也无法访问
- Broadcast Receiver广播基础
- .net C#中页面之间传值传参的六种方法
- JS实现省市区三级联动