Netty自动分解协议
来源:互联网 发布:java 运行时代理 编辑:程序博客网 时间:2024/06/05 02:56
Netty自动分解协议Netty 处理多个协议public static class ProtocolHeadAdapter extends ChannelInboundHandlerAdapter {// 1 GET 请求指定的页面信息,并返回实体主体。// 2 HEAD 类似于get请求,只不过返回的响应中没有具体的内容,用于获取报头// 3 POST// 向指定资源提交数据进行处理请求(例如提交表单或者上传文件)。数据被包含在请求体中。POST请求可能会导致新的资源的建立和/或已有资源的修改。// 4 PUT 从客户端向服务器传送的数据取代指定的文档的内容。// 5 DELETE 请求服务器删除指定的页面。// 6 CONNECT HTTP/1.1协议中预留给能够将连接改为管道方式的代理服务器。// 7 OPTIONS 允许客户端查看服务器的性能。// 8 TRACE 回显服务器收到的请求,主要用于测试或诊断。final static String[] http_head = { "GET ", "HEAD ", "POST ", "PUT ", "DELETE ", "CONNECT ", "OPTIONS ","TRACE " };final static byte[] mqtt_head = { 0x10, 0x00, 0x00, 0x00, 'M', 'Q', 'T', 'T' };void callDecode(ChannelHandlerContext ctx, ByteBuf in) {if (!in.isReadable())return;if (in.readableBytes() < 10) {return;}in.markReaderIndex();byte[] head = new byte[10];in.readBytes(head);in.resetReaderIndex();int i;int sum = 0;// mqttfor (i = 0; i < mqtt_head.length; i++) {if (mqtt_head[i] == head[i] || mqtt_head[i] == 0) {sum++;}}ChannelPipeline pipeline = ctx.pipeline();if (sum == mqtt_head.length) {pipeline.addLast("MqttDecoder", new MqttDecoder());pipeline.addLast("MqttEncoder", MqttEncoder.INSTANCE);pipeline.addLast("MqttServerHandler", new MqttServerHandler(mqttSessionManagent));} else {pipeline.addLast(new HttpServerCodec());pipeline.addLast(new HttpObjectAggregator(65536));pipeline.addLast(new ChunkedWriteHandler());pipeline.addLast(new HttpStaticFileServerHandler());}pipeline.remove(this);}@Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {if (msg instanceof ByteBuf) {try {ByteBuf data = (ByteBuf) msg;callDecode(ctx, data);} catch (DecoderException e) {throw e;} catch (Throwable t) {throw new DecoderException(t);} finally {}} else {ctx.fireChannelRead(msg);}super.channelRead(ctx, msg);}}
阅读全文
0 0
- Netty自动分解协议
- Netty自定义协议开发
- Netty-私有协议栈
- netty 私有协议开发
- netty自定义协议解码
- MessageToMessageDecoder netty自定义协议
- Netty 协议开发
- Netty私有栈协议
- netty实现webSocket协议
- netty自定义协议
- 远程服务协议-netty协议
- Netty In Action 读书笔记 - 第三章 分解Netty
- Netty之http协议开发
- Netty之HTTP协议开发
- Netty之WebSocket协议开发
- Netty的HTTP协议开发
- Netty之WebSocket协议开发
- netty私有协议的开发
- Flask框架知识系列之三
- 将数据快速读入R—readr和readxl包
- Java设计模式-工厂方法模式
- RF-常用关键字-sleep
- TCP/IP三次握手 四次挥手
- Netty自动分解协议
- 深刻理解双重检查锁定(double-checked locking)与单例模式
- 今天的题
- 从弧长的计算到逆时针与顺时针旋转的定义 (二维空间)
- 获取国外电话途径的方法(电话号码可以注册google账号)
- Android数据库(一) 数据库基本使用
- c++和Java哪个比较好入门
- 可靠 UDP 传输
- Sqoop1.x安装部署