On 10/26/07, johnnyv_cn <[EMAIL PROTECTED]> wrote:
>
> Dear all,
> I am using MINA in my project to implement a TCP server.  The server needs
> to hold long-lived connections with clients. The server and clients use
> HTTP-like protocol to exchange xml messages. Here is a simlified message
> example:
>
> POST / HTTP/1.1
> Content-Length: 69
>
> <?xml version="1.0" encoding="utf-8"?><Event><Header/><Body/></Event>
>
> "Content-Length" is used to detect the end of a message.
> My problem is:
> 1. If "Content-Length" is incorrect, how can I determine the end of the
> message? Or, just return "Bad Request"? Using "</Event>" is not allowed
> because not all messages end with "</Event>".

If you know the format of the content, you also know the real length
of the content, which means you don't need to rely on the
Content-Length header.  Otherwise, I think there's no way to take care
of this case.

> 2. If the message is too large, will the message buffer(ByteBuffer) be
> over-filled? How can I prevent this from crashing my program?

Your protocol decoder could write a message with an intermediate
buffer to the ProtocolDecoderOutput.  Once messageReceived event
arrives to the IoHandler, the IoHandler could consume the intermediate
buffer (i.e. get and compact on the buffer).  If more data is
received, the decoder could write the same message again after
appending the received data to the intermediate buffer, and so on.
Some synchronization will be required and the message object must have
a boolean property that determines the whole message is received or
not, but it should be easy to implement.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Reply via email to