lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Mar 6, 2011 at 9:46 AM, Jayanth Acharya <jayachar88@gmail.com> wrote:
> What I would like to understand is how to deal with receive buffers in Lua,

Not sure what this means.

> how to to stitch together segmented TCP data to identify message boundaries
> (given message-length in the application protocol) etc. The message is all

Look at the receive() docs for tcp. You can do a read, specifying the
size of the fixed size header.

Then use struct or pack (search on luaforge) to decode the size from
the header, and read
the rest of the PDU.

luasocket will read repeatedly until it gets end-of-stream or the
amount of data you asked for. If you are dealing with multiple
streams, use select, set timeouts, and collect and concatenate the
partial data.

> binary data, and need to do lot of byte-order (htonX / ntohX) corrections
> etc. I'd prefer the example to be pure Lua, and using LuaSocket.

After you try you'll be well positioned to repost with specific questions.

Cheers,
Sam