Hi:<br>I just write an example based on telnet example code in netty codebase. I hope that can help you. I just implement oneway message processing(client to server). You can test the code using your client program from other programming language. If there is still problem, maybe your client program don&#39;t follow the message format you specified. For example, when you write a length field into socket, in other programming language, the number you write may be not 4  bytes long.<br>
<br>yanky<br><br><br><div class="gmail_quote">2009/4/18 yanky young <span dir="ltr">&lt;<a href="mailto:yanky.young@gmail.com">yanky.young@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi:<br><br>Another class maybe u missed in zipped file: LoggingAgentNettyPipelineFactory<br><br>yanky<br><br><div class="gmail_quote">2009/4/18 manishr22 <span dir="ltr">&lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;</span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hi,<br>
<br>
Trying to attach once again. otherwise i will copy post the java classes in the next post.<br>
<br>
Rest all description is given in previous post.<br>
<br>
Regards<br>
Manish netty+code.zip netty+code.zip<br>
<div><div></div><div><br>
<br>
Hi:<br>
<br>
why i can&#39;t see your attached code? maybe upload problem?<br>
<br>
yanky<br>
<br>
2009/4/17 manishr22 &lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;<br>
<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Hi:<br>
&gt;<br>
&gt;<br>
&gt; Hi yanky,<br>
&gt;<br>
&gt; please find attached code-base for the netty server.<br>
&gt;<br>
&gt; As i mentioned before my client is normal TCP client and sending the<br>
&gt; message in that is sending the data in following format<br>
&gt;<br>
&gt; [MESSAGE 1][4 byte message length][4 bytes header length][header data][body<br>
&gt; data]<br>
&gt;<br>
&gt; [MESSAGE 2][4 byte message length][4 bytes header length][header data][body<br>
&gt; data]<br>
&gt;<br>
&gt; [MESSAGE 3] [4 byte message length][4 bytes header length][header<br>
&gt; data][body data]<br>
&gt; ...<br>
&gt; ...<br>
&gt; ...<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Since my test client code is a bit clumsy.. like how the message-structure<br>
&gt; has been created. so i am not attaching the test client code. But you can<br>
&gt; test this from a normal TCp client by sending the data in the same way as i<br>
&gt; mentioned above..<br>
&gt;<br>
&gt; then for more testing please try running multiple instances of client and<br>
&gt; all are sending say 100 same-messages each and see how netty can handle<br>
&gt; this.<br>
&gt;<br>
&gt;<br>
&gt; Please let me know if you find problem in my server code and if you make<br>
&gt; changes then send me back the code with the test clietn too. with whom you<br>
&gt; will do the testing.<br>
&gt;<br>
&gt;<br>
&gt; Your help is always appreciated..<br>
&gt;<br>
&gt; Thanks<br>
&gt; Manish Ranjan netty+code.zip<br>
&gt;<br>
&gt;<br>
&gt; Would you mind sending me your code? so that I can get to know what the<br>
&gt; problem really is.<br>
&gt;<br>
&gt; thanks<br>
&gt;<br>
&gt; yanky<br>
&gt;<br>
&gt;<br>
&gt; 2009/4/16 manishr22 &lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt; Hi,<br>
&gt; &gt;<br>
&gt; &gt; Please suggest something about my problem.<br>
&gt; &gt;<br>
&gt; &gt; Regards<br>
&gt; &gt; Manish<br>
&gt; &gt;<br>
&gt; &gt; Hi yanky,<br>
&gt; &gt;<br>
&gt; &gt; The problem remains the same. I see my ChannelBuffer capacity is always<br>
&gt; &gt; 1024 though i am writing bigger data from client.So that again I see the<br>
&gt; &gt; same problem as before.<br>
&gt; &gt;<br>
&gt; &gt; Could you please help me in understanding the flow of decode() method?<br>
&gt; &gt; Though i read it but if you explain that may correct my understanding.<br>
&gt; &gt;<br>
&gt; &gt; As i understood, whenever buffer.resetReaderIndex(); encountered,<br>
&gt; decode()<br>
&gt; &gt; method get called again, this means my message-length and header-length<br>
&gt; &gt; variable will again re-initialize with the first 4-4 bytes respectively<br>
&gt; of<br>
&gt; &gt; the current buffer readIndex position. which should never happen. once i<br>
&gt; red<br>
&gt; &gt; the header and message-length my application should first read that<br>
&gt; message<br>
&gt; &gt; and then only go for next message reading operation.<br>
&gt; &gt;<br>
&gt; &gt; say my client is sending data like<br>
&gt; &gt;<br>
&gt; &gt; [MESSAGE 1][4 byte message length][4 bytes header length][header][body]<br>
&gt; &gt; [MESSAGE 2][4 byte message length][4 bytes header length][header][body]<br>
&gt; &gt; [MESSAGE 3] [4 byte message length][4 bytes header<br>
&gt; &gt; length][header][body].......<br>
&gt; &gt;<br>
&gt; &gt; Since multiple clients will se sending data in same fashion so my Netty<br>
&gt; &gt; server should understand them all.<br>
&gt; &gt;<br>
&gt; &gt; Note: Right now my test client is not written using netty api and simply<br>
&gt; &gt; writing message on socket, will that make any difference?<br>
&gt; &gt;<br>
&gt; &gt; I am really sorry to bug more, since i am learning Netty, so i have so<br>
&gt; many<br>
&gt; &gt; questions.<br>
&gt; &gt;<br>
&gt; &gt; Regards<br>
&gt; &gt; Manish<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Hi:<br>
&gt; &gt;<br>
&gt; &gt; Maybe you can have a look at ChannelBuffer interface document. I am not<br>
&gt; &gt; sure<br>
&gt; &gt; I have got it right. But I am trying to correct your code according to my<br>
&gt; &gt; understanding. Some resetReaderIndex methods have been commented out for<br>
&gt; &gt; correction. You can try it. Please let me know if it works.<br>
&gt; &gt;<br>
&gt; &gt; good luck<br>
&gt; &gt;<br>
&gt; &gt; yanky<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; public class LoggingAgentMessageDecoder extends FrameDecoder {<br>
&gt; &gt;<br>
&gt; &gt;       private int maxMsgLenToRead = Constants.LOG_AGENT_MAXIMUM_MSG_LEN;<br>
&gt; &gt;<br>
&gt; &gt;       private Logger logger = Logger.getLogger(this.getClass());<br>
&gt; &gt;<br>
&gt; &gt;       @Override<br>
&gt; &gt;        protected Object decode(ChannelHandlerContext ctx, Channel<br>
&gt; channel,<br>
&gt; &gt;                        ChannelBuffer buffer) throws Exception {<br>
&gt; &gt;<br>
&gt; &gt;               ChannelBuffer[] frame = new ChannelBuffer[2];<br>
&gt; &gt;<br>
&gt; &gt;               // Make sure if the body length field was received.<br>
&gt; &gt;               if (buffer.readableBytes() &lt; 4) {<br>
&gt; &gt;                       return null;<br>
&gt; &gt;               }<br>
&gt; &gt;               // The length field is in the buffer.<br>
&gt; &gt;<br>
&gt; &gt;               // Mark the current buffer position before reading the<br>
&gt; length<br>
&gt; &gt; field<br>
&gt; &gt;               buffer.markReaderIndex();<br>
&gt; &gt;               // Read the length field.<br>
&gt; &gt;               int messageLength = buffer.readInt();<br>
&gt; &gt;               <a href="http://logger.info" target="_blank">logger.info</a>(&quot;Total message lenth is &quot; + messageLength);<br>
&gt; &gt;<br>
&gt; &gt;               // Make sure if the message length field was received.<br>
&gt; &gt;               if (buffer.readableBytes() &lt; 4) {<br>
&gt; &gt;                       // if not enough bytes, we should reset reader<br>
&gt; index<br>
&gt; &gt; to ensure we can read header length field again at the next time when<br>
&gt; this<br>
&gt; &gt; decode method is invoked<br>
&gt; &gt;                       buffer.resetReaderIndex();<br>
&gt; &gt;                       return null;<br>
&gt; &gt;               }<br>
&gt; &gt;               // buffer.markReaderIndex(); // not needed here<br>
&gt; &gt;               int headerLength = buffer.readInt();<br>
&gt; &gt;               <a href="http://logger.info" target="_blank">logger.info</a>(&quot;Total message lenth is &quot; + headerLength);<br>
&gt; &gt;<br>
&gt; &gt;               // buffer.resetReaderIndex(); // not needed here<br>
&gt; &gt;               if (buffer.readableBytes() &lt; headerLength) {<br>
&gt; &gt;                       // The whole bytes were not received yet - return<br>
&gt; &gt; null.<br>
&gt; &gt;                       // This method will be invoked again when more<br>
&gt; &gt; packets are<br>
&gt; &gt;                       // received and appended to the buffer.<br>
&gt; &gt;<br>
&gt; &gt;                       // Reset to the marked position to read the length<br>
&gt; &gt; field again<br>
&gt; &gt;                       // next time.<br>
&gt; &gt;                       buffer.resetReaderIndex(); // yes, this time we<br>
&gt; need<br>
&gt; &gt; to reset reader index to read all bytes again<br>
&gt; &gt;<br>
&gt; &gt;                       return null;<br>
&gt; &gt;               }<br>
&gt; &gt;               frame[0] = buffer.readBytes(headerLength);<br>
&gt; &gt;               // buffer.resetReaderIndex();  // not needed here<br>
&gt; &gt;               System.out.println(&quot;Bufer capacity is &quot; +<br>
&gt; buffer.capacity());<br>
&gt; &gt;               if (buffer.readableBytes() &lt; messageLength) {<br>
&gt; &gt;                       // The whole bytes were not received yet - return<br>
&gt; &gt; null.<br>
&gt; &gt;                       // This method will be invoked again when more<br>
&gt; &gt; packets are<br>
&gt; &gt;                       // received and appended to the buffer.<br>
&gt; &gt;<br>
&gt; &gt;                       // Reset to the marked position to read the length<br>
&gt; &gt; field again<br>
&gt; &gt;                       // next time.<br>
&gt; &gt;<br>
&gt; &gt;                       // control is coming inside this since the capacity<br>
&gt; &gt; fo channelbuffer<br>
&gt; &gt;                       // is always less then the total message length.<br>
&gt; &gt;                       buffer.resetReaderIndex(); // yes, again we need to<br>
&gt; &gt; reset<br>
&gt; &gt;<br>
&gt; &gt;                       return null;<br>
&gt; &gt;               }<br>
&gt; &gt;<br>
&gt; &gt;               // There&#39;s enough bytes in the buffer. Read it.<br>
&gt; &gt;               frame[1] = buffer.readBytes(messageLength);<br>
&gt; &gt;               // TODO: need to add the logic to get the data parsed and<br>
&gt; add<br>
&gt; &gt; into<br>
&gt; &gt;               // activeAMQ<br>
&gt; &gt;               return frame;<br>
&gt; &gt;       }<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; 2009/4/14 manishr22 &lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;<br>
&gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Still this one is not able to solve this problem.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; The message comes from my server has proper format like:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; First 4 byte has information about body length. for example 1173<br>
&gt; &gt; &gt; Next 4 byte has length of header for example 92<br>
&gt; &gt; &gt; now in next 92 bytes i have my message header.<br>
&gt; &gt; &gt; and then from 100th byte onward i have my message body till 1173 byte.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; To solve this I have written my decoder and tried solving it like:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; public class LoggingAgentMessageDecoder extends FrameDecoder {<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;        private int maxMsgLenToRead =<br>
&gt; Constants.LOG_AGENT_MAXIMUM_MSG_LEN;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;        private Logger logger = Logger.getLogger(this.getClass());<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;        @Override<br>
&gt; &gt; &gt;         protected Object decode(ChannelHandlerContext ctx, Channel<br>
&gt; &gt; channel,<br>
&gt; &gt; &gt;                         ChannelBuffer buffer) throws Exception {<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                ChannelBuffer[] frame = new ChannelBuffer[2];<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                // Make sure if the message length field was received.<br>
&gt; &gt; &gt;                if (buffer.readableBytes() &lt; 4) {<br>
&gt; &gt; &gt;                        return null;<br>
&gt; &gt; &gt;                }<br>
&gt; &gt; &gt;                // The length field is in the buffer.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                // Mark the current buffer position before reading the<br>
&gt; &gt; &gt; length field<br>
&gt; &gt; &gt;                buffer.markReaderIndex();<br>
&gt; &gt; &gt;                // Read the length field.<br>
&gt; &gt; &gt;                int messageLength = buffer.readInt();<br>
&gt; &gt; &gt;                <a href="http://logger.info" target="_blank">logger.info</a>(&quot;Total message lenth is &quot; + messageLength);<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                // Make sure if the message length field was received.<br>
&gt; &gt; &gt;                if (buffer.readableBytes() &lt; 4) {<br>
&gt; &gt; &gt;                        return null;<br>
&gt; &gt; &gt;                }<br>
&gt; &gt; &gt;                buffer.markReaderIndex();<br>
&gt; &gt; &gt;                int headerLength = buffer.readInt();<br>
&gt; &gt; &gt;                <a href="http://logger.info" target="_blank">logger.info</a>(&quot;Total message lenth is &quot; + headerLength);<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                buffer.resetReaderIndex();<br>
&gt; &gt; &gt;                if (buffer.readableBytes() &lt; headerLength) {<br>
&gt; &gt; &gt;                        // The whole bytes were not received yet -<br>
&gt; return<br>
&gt; &gt; &gt; null.<br>
&gt; &gt; &gt;                        // This method will be invoked again when more<br>
&gt; &gt; &gt; packets are<br>
&gt; &gt; &gt;                        // received and appended to the buffer.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                        // Reset to the marked position to read the<br>
&gt; length<br>
&gt; &gt; &gt; field again<br>
&gt; &gt; &gt;                        // next time.<br>
&gt; &gt; &gt;                        buffer.resetReaderIndex();<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                        return null;<br>
&gt; &gt; &gt;                }<br>
&gt; &gt; &gt;                frame[0] = buffer.readBytes(headerLength);<br>
&gt; &gt; &gt;                buffer.resetReaderIndex();<br>
&gt; &gt; &gt;                System.out.println(&quot;Bufer capacity is &quot; +<br>
&gt; &gt; &gt; buffer.capacity());<br>
&gt; &gt; &gt;                if (buffer.readableBytes() &lt; messageLength) {<br>
&gt; &gt; &gt;                        // The whole bytes were not received yet -<br>
&gt; return<br>
&gt; &gt; &gt; null.<br>
&gt; &gt; &gt;                        // This method will be invoked again when more<br>
&gt; &gt; &gt; packets are<br>
&gt; &gt; &gt;                        // received and appended to the buffer.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                        // Reset to the marked position to read the<br>
&gt; length<br>
&gt; &gt; &gt; field again<br>
&gt; &gt; &gt;                        // next time.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                        // control is coming inside this since the<br>
&gt; &gt; capacity<br>
&gt; &gt; &gt; fo channelbuffer<br>
&gt; &gt; &gt;                        // is always less then the total message length.<br>
&gt; &gt; &gt;                        buffer.resetReaderIndex();<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                        return null;<br>
&gt; &gt; &gt;                }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;                // There&#39;s enough bytes in the buffer. Read it.<br>
&gt; &gt; &gt;                frame[1] = buffer.readBytes(messageLength);<br>
&gt; &gt; &gt;                // TODO: need to add the logic to get the data parsed<br>
&gt; and<br>
&gt; &gt; &gt; add into<br>
&gt; &gt; &gt;                // activeAMQ<br>
&gt; &gt; &gt;                return frame;<br>
&gt; &gt; &gt;        }<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; But the problem in this i see is whenever the controls come to if<br>
&gt; &gt; statement<br>
&gt; &gt; &gt; which goes to read my body i see buffer.readableBytes() is always 1020<br>
&gt; &gt; and<br>
&gt; &gt; &gt; since my body length is greater than this it goes inside the if<br>
&gt; condition<br>
&gt; &gt; &gt; and call the method buffer.resetReaderIndex().<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; This actually recall the whole decode method again and then<br>
&gt; re-initialize<br>
&gt; &gt; &gt; the value for message-length and header-length to the wrong value like<br>
&gt; &gt; &gt; message length as 92 and after that 262145.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; and this all mess up completely. for my testing from client i am<br>
&gt; actually<br>
&gt; &gt; &gt; sending only one data which message header of 92 byte and body as 1173<br>
&gt; &gt; &gt; bytes.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; so i am not sure how come in different iteration the message length<br>
&gt; gets<br>
&gt; &gt; &gt; increased.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; i see always the capacity the the ChannelBuffer comes as 1024 though i<br>
&gt; am<br>
&gt; &gt; &gt; not setting the limit to channelBuffer.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Please suggest what wrong i am doing?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Regards<br>
&gt; &gt; &gt; Manish<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Hi:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; You have a schema in your message. So while encoding and decoding, you<br>
&gt; &gt; have<br>
&gt; &gt; &gt; to recognize a complete request or response message. A common practice<br>
&gt; is<br>
&gt; &gt; &gt; to<br>
&gt; &gt; &gt; use another delimiter that&#39;s usually not used in protocol message to<br>
&gt; mark<br>
&gt; &gt; &gt; the boundary of different protocol messages. Fortunately, netty do has<br>
&gt; &gt; &gt; out-of-box support for this problem. You can have a look at<br>
&gt; &gt; example.telnet<br>
&gt; &gt; &gt; package and also codec.frame package to see how<br>
&gt; &gt; DelimiterBasedFrameDecoder<br>
&gt; &gt; &gt; can work for you.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Another consideration is that, you have a xml message, of course it is<br>
&gt; &gt; &gt; string, but you can build your own encoder and decoder to translate<br>
&gt; POJO<br>
&gt; &gt; &gt; from/to xml string and then xml string from/to ChannelBuffer. That<br>
&gt; would<br>
&gt; &gt; be<br>
&gt; &gt; &gt; better. I think it would be like this:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; in your PipelineFactory:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; // this factory should be used for both client and server to setup<br>
&gt; &gt; pipeline<br>
&gt; &gt; &gt; public ChannelPipeline getPipeline() throws Exception {<br>
&gt; &gt; &gt;        ChannelPipeline pipeline = pipeline();<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;        final int xmlMessageSizeLimit  = 8192; // can be modified to<br>
&gt; meet<br>
&gt; &gt; &gt; your needs<br>
&gt; &gt; &gt;        // Add the text line codec combination first,<br>
&gt; &gt; &gt;        pipeline.addLast(&quot;framer&quot;, new DelimiterBasedFrameDecoder(<br>
&gt; &gt; &gt;                xmlMessageSizeLimit, Delimiters.nulDelimiter()));<br>
&gt; &gt; &gt;        pipeline.addLast(&quot;decoder&quot;, new MyProtocolDecoder());<br>
&gt; &gt; &gt;        pipeline.addLast(&quot;encoder&quot;, new MyProtocolEncoder());<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;        // and then business logic.<br>
&gt; &gt; &gt;        pipeline.addLast(&quot;handler&quot;, handler);<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; and then define your own encoder and decoder:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; public class MyProtocolDecoder extends StringDecoder{<br>
&gt; &gt; &gt;      //just override decode method<br>
&gt; &gt; &gt;      protected Object decode(<br>
&gt; &gt; &gt;            ChannelHandlerContext ctx, Channel channel, Object msg)<br>
&gt; throws<br>
&gt; &gt; &gt; Exception {<br>
&gt; &gt; &gt;        String xml = super(ctx, channel, msg);<br>
&gt; &gt; &gt;        // then use any xml parser or xml binding tool to map xml to<br>
&gt; your<br>
&gt; &gt; &gt; POJO, I use XStream as example<br>
&gt; &gt; &gt;        XStream mapper = new XStream();<br>
&gt; &gt; &gt;        mapper.alias(&quot;header&quot;,<br>
&gt; MyProtocolMessage.MyProtocolHeader.class);<br>
&gt; &gt; &gt;        mapper.alias(&quot;body&quot;, MyProtocolMessage.MyProtocolBody.class);<br>
&gt; &gt; &gt;        MyProtocolMessage protoMsg = mapper.fromXML(xml);<br>
&gt; &gt; &gt;        return protoMsg;<br>
&gt; &gt; &gt;    }<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; public class MyProtocolMessage {<br>
&gt; &gt; &gt;   MyProtocolHeader header;<br>
&gt; &gt; &gt;   MyProtocolBody body;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;   static class MyProtocolHeader {......}<br>
&gt; &gt; &gt;   static class MyProtocolBody {......}<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; you should do the reverse process in MyProtocolEncoder<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Hope it helps.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; good luck<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; yanky<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; 2009/4/13 manishr22 &lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; How I can read a chunk of data from channel using netty api? my<br>
&gt; client<br>
&gt; &gt; is<br>
&gt; &gt; &gt; &gt; writing every time on socket<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &lt;manish&gt; welcome to the real world&lt;/manish&gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; and my netty server needs to read the message till &lt;/manish&gt; in one<br>
&gt; go.<br>
&gt; &gt; &gt; and<br>
&gt; &gt; &gt; &gt; then next message starting from &lt;manish&gt; should be read by Netty<br>
&gt; &gt; server.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Any code snippet would be a great help.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; In my decoder if i read the message from channelbuffer using<br>
&gt; getbytes()<br>
&gt; &gt; &gt; api<br>
&gt; &gt; &gt; &gt; i see the data but not able to get i can read the whole message in<br>
&gt; one<br>
&gt; &gt; &gt; go. i<br>
&gt; &gt; &gt; &gt; do see sometime some extra message being read from channel. any<br>
&gt; reason<br>
&gt; &gt; &gt; why<br>
&gt; &gt; &gt; &gt; it should be.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Thanks in advance.<br>
&gt; &gt; &gt; &gt; Regards<br>
&gt; &gt; &gt; &gt; Manish<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Hi Yanky,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Thanks so much for your guidance. I will look into factorial example<br>
&gt; &gt; will<br>
&gt; &gt; &gt; &gt; solving my problem based on this.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; For any further help, if needed i will post my request here.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Thanks again<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Manish<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Thanks Yanky for the great answer!  So nice that you are here as a<br>
&gt; &gt; &gt; &gt; part of the community.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Cheers,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; — Trustin Lee, <a href="http://gleamynode.net/" target="_blank">http://gleamynode.net/</a><br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; On Sat, Apr 11, 2009 at 3:16 AM, yanky young &lt;<a href="mailto:yanky.young@gmail.com" target="_blank">yanky.young@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; Hi:<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; I am not netty expert yet. I am just trying to give some hints. In<br>
&gt; &gt; your<br>
&gt; &gt; &gt; &gt; &gt; case, you are actually building a request/response protocol. And<br>
&gt; &gt; &gt; request<br>
&gt; &gt; &gt; &gt; and<br>
&gt; &gt; &gt; &gt; &gt; response message may include quite complicated headers and body. So<br>
&gt; &gt; you<br>
&gt; &gt; &gt; &gt; have<br>
&gt; &gt; &gt; &gt; &gt; to do some message encoding and decoding in both server side and<br>
&gt; &gt; client<br>
&gt; &gt; &gt; &gt; &gt; side. You can see in netty codebase there are some out-of-box<br>
&gt; encoder<br>
&gt; &gt; &gt; and<br>
&gt; &gt; &gt; &gt; &gt; decoder in handler.codec package. I suggest you take a look at<br>
&gt; &gt; &gt; &gt; &gt; example.fractorial package to see how to implement your own encoder<br>
&gt; &gt; and<br>
&gt; &gt; &gt; &gt; &gt; decoder for your message format which may be xml. If you are not<br>
&gt; &gt; &gt; &gt; sensitive<br>
&gt; &gt; &gt; &gt; &gt; to message format, you can also have a look at example.localtime<br>
&gt; &gt; which<br>
&gt; &gt; &gt; &gt; use<br>
&gt; &gt; &gt; &gt; &gt; google protobuf library as real encoder and decoder.<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; good luck<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; yanky<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; 2009/4/11 manishr22 &lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; Hi Yanky,<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; I took the sample code from svn trunk and saw the codes too. Could<br>
&gt; &gt; you<br>
&gt; &gt; &gt; &gt; &gt;&gt; please let me know which one among given sample code will fit for<br>
&gt; &gt; the<br>
&gt; &gt; &gt; &gt; &gt;&gt; reference of my requirement.<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; Regards,<br>
&gt; &gt; &gt; &gt; &gt;&gt; Manish<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; Hi:<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; Of course there are some sample code in netty project. You can<br>
&gt; just<br>
&gt; &gt; &gt; &gt; check<br>
&gt; &gt; &gt; &gt; &gt;&gt; out the svn trunk and see some samples in example package.<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; good luck<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; yanky<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; 2009/4/10 manishr22 &lt;<a href="mailto:manishr22@gmail.com" target="_blank">manishr22@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; Hi,<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; I had a problem statement<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; &quot;to write an asynchronous TCP server to which multiple clients<br>
&gt; &gt; will<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; connect<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; and keep sending messages to my tcp server. My server should<br>
&gt; read<br>
&gt; &gt; &gt; the<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; message and send back some acknowledgment information to the<br>
&gt; &gt; client<br>
&gt; &gt; &gt; &gt; who<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; sent<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; the data. While reading the data at server since the message<br>
&gt; comes<br>
&gt; &gt; &gt; in<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; particular format i have to do some processing before sending<br>
&gt; the<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; response<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; back to client.&quot;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; say my client is sending a message structure in which it has<br>
&gt; some<br>
&gt; &gt; &gt; &gt; header<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; and then in body it has message like :<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; &lt;manish&gt;welcome to the real world&lt;/manish&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; I was on the way to implement NIO but in between i found such a<br>
&gt; &gt; &gt; great<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; library netty and thought of using it. i was trying to make use<br>
&gt; of<br>
&gt; &gt; &gt; &gt; this<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; library with the given tutorial and examples but i found that<br>
&gt; &gt; &gt; tutorial<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; is<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; not good enough to solve the complex problem.<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; If you can provide me some guidance or sample code that how i<br>
&gt; &gt; should<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; solve<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; my problem using netty library, that would be great.<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; Thanks in advance.<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; Regards<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; Manish<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; --<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; View this message in context:<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2615889.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2615889.html</a><br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; Sent from the Netty User Group mailing list archive at<br>
&gt; Nabble.com.<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; netty-users mailing list<br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt; &gt; &gt;&gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; _______________________________________________<br>
&gt; &gt; &gt; &gt; &gt;&gt; netty-users mailing list<br>
&gt; &gt; &gt; &gt; &gt;&gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; &gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; --<br>
&gt; &gt; &gt; &gt; &gt;&gt; View this message in context:<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2617267.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2617267.html</a><br>
&gt; &gt; &gt; &gt; &gt;&gt; Sent from the Netty User Group mailing list archive at Nabble.com.<br>
&gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt;&gt; _______________________________________________<br>
&gt; &gt; &gt; &gt; &gt;&gt; netty-users mailing list<br>
&gt; &gt; &gt; &gt; &gt;&gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; &gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; &gt; &gt; netty-users mailing list<br>
&gt; &gt; &gt; &gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; &gt; netty-users mailing list<br>
&gt; &gt; &gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; --<br>
&gt; &gt; &gt; &gt; View this message in context:<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2627351.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2627351.html</a><br>
&gt; &gt; &gt; &gt; Sent from the Netty User Group mailing list archive at Nabble.com.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; &gt; netty-users mailing list<br>
&gt; &gt; &gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; netty-users mailing list<br>
&gt; &gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; --<br>
&gt; &gt; &gt; View this message in context:<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2632783.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2632783.html</a><br>
&gt; &gt; &gt; Sent from the Netty User Group mailing list archive at Nabble.com.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; netty-users mailing list<br>
&gt; &gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; netty-users mailing list<br>
&gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; View this message in context:<br>
&gt; &gt;<br>
&gt; <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2642120.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2642120.html</a><br>
&gt; &gt; Sent from the Netty User Group mailing list archive at Nabble.com.<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; netty-users mailing list<br>
&gt; &gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt; &gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; netty-users mailing list<br>
&gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; View this message in context:<br>
&gt; <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2650632.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2650632.html</a><br>
&gt; Sent from the Netty User Group mailing list archive at Nabble.com.<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; netty-users mailing list<br>
&gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
&gt;<br>
<br>
_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
<br>
<br>
<br>
--<br>
</div></div>View this message in context: <a href="http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2654456.html" target="_blank">http://n2.nabble.com/Code-example-to-write-asynchronous-server-tp2615889p2654456.html</a><br>


<div><div></div><div>Sent from the Netty User Group mailing list archive at Nabble.com.<br>
<br>
<br>
_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
</div></div></blockquote></div></div></div><br>
</blockquote></div><br>