- 浏览: 2654775 次
- 来自: 杭州
文章分类
- 全部博客 (1188)
- webwork (4)
- 网摘 (18)
- java (103)
- hibernate (1)
- Linux (85)
- 职业发展 (1)
- activeMQ (2)
- netty (14)
- svn (1)
- webx3 (12)
- mysql (81)
- css (1)
- HTML (6)
- apache (3)
- 测试 (2)
- javascript (1)
- 储存 (1)
- jvm (5)
- code (13)
- 多线程 (12)
- Spring (18)
- webxs (2)
- python (119)
- duitang (0)
- mongo (3)
- nosql (4)
- tomcat (4)
- memcached (20)
- 算法 (28)
- django (28)
- shell (1)
- 工作总结 (5)
- solr (42)
- beansdb (6)
- nginx (3)
- 性能 (30)
- 数据推荐 (1)
- maven (8)
- tonado (1)
- uwsgi (5)
- hessian (4)
- ibatis (3)
- Security (2)
- HTPP (1)
- gevent (6)
- 读书笔记 (1)
- Maxent (2)
- mogo (0)
- thread (3)
- 架构 (5)
- NIO (5)
- 正则 (1)
- lucene (5)
- feed (4)
- redis (17)
- TCP (6)
- test (0)
- python,code (1)
- PIL (3)
- guava (2)
- jython (4)
- httpclient (2)
- cache (3)
- signal (1)
- dubbo (7)
- HTTP (4)
- json (3)
- java socket (1)
- io (2)
- socket (22)
- hash (2)
- Cassandra (1)
- 分布式文件系统 (5)
- Dynamo (2)
- gc (8)
- scp (1)
- rsync (1)
- mecached (0)
- mongoDB (29)
- Thrift (1)
- scribe (2)
- 服务化 (3)
- 问题 (83)
- mat (1)
- classloader (2)
- javaBean (1)
- 文档集合 (27)
- 消息队列 (3)
- nginx,文档集合 (1)
- dboss (12)
- libevent (1)
- 读书 (0)
- 数学 (3)
- 流程 (0)
- HBase (34)
- 自动化测试 (1)
- ubuntu (2)
- 并发 (1)
- sping (1)
- 图形 (1)
- freemarker (1)
- jdbc (3)
- dbcp (0)
- sharding (1)
- 性能测试 (1)
- 设计模式 (2)
- unicode (1)
- OceanBase (3)
- jmagick (1)
- gunicorn (1)
- url (1)
- form (1)
- 安全 (2)
- nlp (8)
- libmemcached (1)
- 规则引擎 (1)
- awk (2)
- 服务器 (1)
- snmpd (1)
- btrace (1)
- 代码 (1)
- cygwin (1)
- mahout (3)
- 电子书 (1)
- 机器学习 (5)
- 数据挖掘 (1)
- nltk (6)
- pool (1)
- log4j (2)
- 总结 (11)
- c++ (1)
- java源代码 (1)
- ocr (1)
- 基础算法 (3)
- SA (1)
- 笔记 (1)
- ml (4)
- zokeeper (0)
- jms (1)
- zookeeper (5)
- zkclient (1)
- hadoop (13)
- mq (2)
- git (9)
- 问题,io (1)
- storm (11)
- zk (1)
- 性能优化 (2)
- example (1)
- tmux (1)
- 环境 (2)
- kyro (1)
- 日志系统 (3)
- hdfs (2)
- python_socket (2)
- date (2)
- elasticsearch (1)
- jetty (1)
- 树 (1)
- 汽车 (1)
- mdrill (1)
- 车 (1)
- 日志 (1)
- web (1)
- 编译原理 (1)
- 信息检索 (1)
- 性能,linux (1)
- spam (1)
- 序列化 (1)
- fabric (2)
- guice (1)
- disruptor (1)
- executor (1)
- logback (2)
- 开源 (1)
- 设计 (1)
- 监控 (3)
- english (1)
- 问题记录 (1)
- Bitmap (1)
- 云计算 (1)
- 问题排查 (1)
- highchat (1)
- mac (3)
- docker (1)
- jdk (1)
- 表达式 (1)
- 网络 (1)
- 时间管理 (1)
- 时间序列 (1)
- OLAP (1)
- Big Table (0)
- sql (1)
- kafka (1)
- md5 (1)
- springboot (1)
- spring security (1)
- Spring Boot (3)
- mybatis (1)
- java8 (1)
- 分布式事务 (1)
- 限流 (1)
- Shadowsocks (0)
- 2018 (1)
- 服务治理 (1)
- 设计原则 (1)
- log (0)
- perftools (1)
最新评论
-
siphlina:
课程——基于Python数据分析与机器学习案例实战教程分享网盘 ...
Python机器学习库 -
san_yun:
leibnitz 写道hi,我想知道,无论在92还是94版本, ...
hbase的行锁与多版本并发控制(MVCC) -
leibnitz:
hi,我想知道,无论在92还是94版本,更新时(如Puts)都 ...
hbase的行锁与多版本并发控制(MVCC) -
107x:
不错,谢谢!
Latent Semantic Analysis(LSA/ LSI)算法简介 -
107x:
不错,谢谢!
Python机器学习库
FrameDecoder 负责 decodes the received
ChannelBuffer
s into a meaningful frame object.
In a stream-based transport such as TCP/IP, packets can be fragmented and reassembled during transmission even in a LAN environment. For example, let us assume you have received three packets:
+-----+-----+-----+ | ABC | DEF | GHI | +-----+-----+-----+
because of the packet fragmentation, a server can receive them like the following:
+----+-------+---+---+ | AB | CDEFG | H | I | +----+-------+---+---+
FrameDecoder
helps you defrag the received packets into one or more meaningful
frames
that could be easily understood by the application logic. In case of the example above, your
FrameDecoder
implementation could defrag the received packets like the following:
+-----+-----+-----+ | ABC | DEF | GHI | +-----+-----+-----+
The following code shows an example handler which decodes a frame whose first 4 bytes header represents the length of the frame, excluding the header.
MESSAGE FORMAT ============== Offset: 0 4 (Length + 4) +--------+------------------------+ Fields: | Length | Actual message content | +--------+------------------------+ DECODER IMPLEMENTATION ====================== public class IntegerHeaderFrameDecoder extends FrameDecoder { protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { // Make sure if the length field was received. if (buf.readableBytes() < 4) { // The length field was not received yet - return null. // This method will be invoked again when more packets are // received and appended to the buffer. return null ; } // The length field is in the buffer. // Mark the current buffer position before reading the length field // because the whole frame might not be in the buffer yet. // We will reset the buffer position to the marked position if // there's not enough bytes in the buffer. buf.markReaderIndex(); // Read the length field. int length = buf.readInt(); // Make sure if there's enough bytes in the buffer. if (buf.readableBytes() < length) { // The whole bytes were not received yet - return null. // This method will be invoked again when more packets are // received and appended to the buffer. // Reset to the marked position to read the length field again // next time. buf.resetReaderIndex(); return null ; } // There's enough bytes in the buffer. Read it. ChannelBuffer frame = buf.readBytes(length); // Successfully decoded a frame. Return the decoded frame. return frame ; } }
Returning a POJO rather than a
ChannelBuffer
Please note that you can return an object of a different type than
ChannelBuffer
in your
decode()
and
decodeLast()
implementation. For example, you could return a
POJO
so that the next
ChannelUpstreamHandler
receives a
MessageEvent
which contains a POJO rather than a
ChannelBuffer
.
Replacing a decoder with another decoder in a pipeline
If you are going to write a protocol multiplexer, you will probably want to replace a
FrameDecoder
(protocol detector) with another
FrameDecoder
or
ReplayingDecoder
(actual protocol decoder). It is not possible to achieve this simply by callingChannelPipeline.replace(ChannelHandler, String, ChannelHandler)
, but some additional steps are required:
public class FirstDecoder extends FrameDecoder { public FirstDecoder() { super(true); // Enable unfold } protected Object decode(ChannelHandlerContext ctx, Channel ch, ChannelBuffer buf) { ... // Decode the first message Object firstMessage = ...; // Add the second decoder ctx.getPipeline().addLast("second", new SecondDecoder()); // Remove the first decoder (me) ctx.getPipeline().remove(this); if (buf.readable()) { // Hand off the remaining data to the second decoder return new Object[] { firstMessage, buf.readBytes(buf.readableBytes()) }; } else { // Nothing to hand off return firstMessage; } } }
发表评论
-
Netty笔记ReplayingDecoder
2013-03-15 11:39 1315为什么需要ReplayingDecoder,它和FrameD ... -
netty StringDecoderTester
2013-02-21 16:55 1033netty package com.duita ... -
netty文档集合
2013-02-10 13:17 1113Netty 3.1 中文用户手册(一)-序言 Netty ... -
TransferQueue
2013-02-08 14:55 1595在看netty的代码实现发 ... -
ChannelBuffer介绍介绍
2012-11-07 11:28 840A random and sequential ... -
netty简单介绍
2012-11-03 20:05 1170ServerBootstrap 启动nett ... -
Netty服务器线程模型概览
2012-10-08 16:57 10878一切从ServerBootstrap开始 ServerB ... -
netty源代码分析
2012-10-08 16:35 965这篇文章(http://san-yun.iteye.com/b ... -
netty ExecutionHandler
2012-10-08 16:34 1526前面(http://san-yun.iteye.com/blo ... -
netty ChannelFuture
2012-10-08 14:12 1339在Netty中所有的io操作都是异步的,这也就是意味任何io访 ... -
netty的一点学习笔记
2012-10-02 22:57 1071原文:http://macrochen.iteye.com/b ... -
Netty实现原理浅析
2012-09-29 15:47 1357Netty是JBoss出品的高效的Java NIO开发框架, ... -
Netty代码分析
2012-09-29 13:22 772参考:http://rdc.taobao.co ... -
netty初探
2011-05-24 15:56 1617netty API //启动类 Server ...
相关推荐
在提供的压缩包文件"粘包和分包及FrameDecoder源码解析.rar"中,你将能够找到对`FrameDecoder`源码的深入分析视频和相关的示例项目。通过观看视频和运行示例,你可以更好地理解`FrameDecoder`的工作原理,以及如何在...
该项目为开源的C#语言实现的SunnyUI.FrameDecoder跨平台流式数据解码库,包含46个文件,包括33个C#源代码文件、5个Markdown文档、3个项目文件、1个Git忽略配置文件、1个许可证文件、1个解决方案文件、1个图标文件和1...
netty-frameDecoder换行符,自定义分隔符,定长度解码器说明使用tcp传送数据,由于缓存区大小的设置,MSS的tcp分段等因素,数据传输时会出现TCP粘包/拆包的问题。但是底层的tcp无法理解上层的业务数据,所以在底层也...
在本文中,我们将深入探讨如何使用C#语言开发一个简易串口调试软件,该软件具有发送和接收数据的功能。此项目特别关注了串口通信、UI界面美化以及UI进程分离等关键技术。 首先,让我们了解串口通信的基础。...
《mina和protobuf整合教程》 在Java开发领域,MINA(Multi-purpose Infrastructure for Network Applications)是一个功能强大的网络应用框架,而Protocol Buffers是Google推出的一种高效的数据序列化协议。...
Netty提供了多种不同策略的FrameDecoder实现,如基于分隔符的FrameDecoder和基于长度字段的FrameDecoder。 最后,ReplayingDecoder是Netty中一个特殊的解码器,它利用了ChannelBuffer的标记和重放特性,简化了粘包...
本示例将详细介绍Netty如何实现心跳检测。 在Netty中,心跳检测通常通过自定义的`FrameDecoder`、`FrameEncoder`和`ChannelInboundHandler`来完成。下面我们将逐步解释这些组件的作用以及如何构建心跳检测机制。 1...
11. **FrameDecoder**:FrameDecoder是Netty中用于解码网络数据包的组件,它将接收到的数据分割成有意义的帧。例如,DelimiterBasedFrameDecoder基于分隔符解码,而LengthFieldBasedFrameDecoder则根据长度字段进行...
服务端通过 `ProtobufVarint32FrameDecoder` 和 `ProtobufDecoder` 解码接收到的数据,然后通过 `ServerHandler` 处理业务逻辑。同样地,我们需要用 `ProtobufVarint32LengthFieldPrepender` 和 `ProtobufEncoder` ...
例如,我们可能会定义一个`FrameDecoder`来分割接收到的数据,以及一个`FrameEncoder`来编码待发送的消息。这些处理器应该能识别并解析特定格式的报头,然后处理消息体。 在自定义协议中引入MessagePack,我们需要...
下面将详细介绍Unity中的Socket通信以及粘包处理的相关知识。 Unity中的Socket通信: Socket是网络编程的基础,它提供了一种进程间通信的方式,使得运行在不同计算机上的程序能够通过网络交换数据。在Unity中,我们...
2. **使用FrameDecoder**:Netty的ChannelInboundHandlerAdapter中有多个预定义的解码器,例如LengthFieldBasedFrameDecoder,它可以基于前导长度字段来拆分消息。用户需要指定长度字段的位置、长度、偏移量等参数,...
以上就是Netty面试专题1中的核心知识点,包括对BIO、NIO、AIO的理解,NIO组件的详细说明,Netty线程模型,TCP粘包/拆包问题的解决,以及序列化协议的介绍。理解这些内容对于深入学习Netty和提升网络编程技能至关重要...
下面将详细介绍如何使用Netty实现心跳检测以及断线后的自动重连功能。 1. **心跳机制** - 心跳包:在网络通信中,心跳包用于检测连接的活性。当连接长时间没有数据传输时,双方可以通过发送心跳包来确认对方是否还...
其中服务器端可能已经实现了自定义的编解码器,但遇到了TCP粘包的问题,这需要开发者深入理解TCP协议,优化编码解码过程,或者利用Netty提供的解决方案,如使用合适的FrameDecoder来避免粘包问题。客户端部分则可能...
- 如何处理粘包和拆包问题,以及如何选择合适的FrameDecoder? 6. **零拷贝** - 什么是零拷贝?Netty是如何实现零拷贝的? - 零拷贝在什么场景下能显著提高性能? 7. **心跳机制** - 在Netty中如何实现心跳...
Netty 提供了 ProtobufVarint32FrameDecoder 和 ProtobufDecoder 等组件,方便在 Netty 应用中使用 Protobuf 进行数据传输。 通过学习这些示例代码和相关博客,开发者可以深入理解 Netty 的工作原理,提高网络编程...
为了解决这个问题,Netty提供了一些内置的FrameDecoder,如LineBasedFrameDecoder。LineBasedFrameDecoder通过识别消息中的特定分隔符(通常是换行符\n或回车换行符\r\n)来分割数据包。这样,我们可以确保每个接收...
然而,这也意味着需要处理TCP粘包和拆包问题,通过自定义的FrameDecoder可以解决这个问题,确保每条消息都能正确解析。 在Android环境下使用Netty,需要注意线程安全和内存管理,因为Android的主线程不能进行耗时...
.frameDecoder(PayloadDecoder.ZERO_COPY) .transport(TcpClientTransport.create(7000)) .start() .block(); } @Bean RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) { return ...