lua-users home
lua-l archive

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

On Fri, Sep 30, 2011 at 10:55 AM, Xavier Wang <> wrote:
> Hi dear list,
> I'm thinking about net game programming in Lua, I have used luasocket
> before, but it blocking in sending/receiving, I have a question, are
> there callback based socket interface in Lua? e.g.
> local s = socket.connect("", 80)
> s:send("GET /\r\n", function(e, chunk)
>    print(e, chunk)
> end)
> that is to register a callback to interface, and when the send/receive
> finished, the callback will called by interface.
> Are there anyone have the same idea or some experience? Thank you :-)

Look at Copas [1] for a coroutine-based version of this. It's not
quite as you describe, but it's written in Lua and you may be able to
adapt it to get what you want, or maybe the coroutine-based method
will seem more attractive to you once you understand it.