lua-users home
lua-l archive

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

On Mon, Jun 22, 2009 at 10:36 AM, Francisco Sant'anna <> wrote:


The documented patterns for client:receive are '*a', '*l', or a number. Is it possible to get everything that is available on the socket in a given moment? (I'm using with all connections with settimeout(0).)

Its harder than it should be. I do this:
-- data, emsg =, pattern[, prefix])
Identical to client:receive(), except that if partial data was read, it returns
it instead of returning nil.
This is convenient for binary/non-line-delimited protocols.
function read(client, pattern, prefix)
  local data, emsg, partial = client:receive(pattern, prefix)
  if data then
    return data
  if partial and #partial > 0 then
    return partial
  return nil, emsg


I couldn't also find in the API a way to check if the client connection with the server is still open.

How would you do that with the underlying C sockets API?