On Tue, Sep 25, 2012 at 8:17 AM, 丁树凯 <
dings...@gmail.com> wrote:
> hi,
>
> These days I want to find a lua socket server as my next game's server.
> luvit is the one I find that is highly active.
> I think you guys are doing wonderful jobs.
Thanks!
>
> I am new to lua and luvit, so my questions may sound naive...
>
> 1. how can i do it in luvit like
soket.io:
>
> var io = require('
socket.io').listen(80);
> io.sockets.on('connection', function (socket) {
> socket.emit('news', { hello: 'world' });
> socket.on('my other event', function (data) {
> console.log(data);
> });
> });
>
>
> I saw the socket echo server under examples/, but I dont know how to do it
> as the code above.
> I wish there were more doc about luvit ..
Sorry there aren't more docs. Basically the luvit APIs in core match
what's in Node.JS core. The docs at
nodejs.org will get you pretty
far. I hope to find time to fix this soon.
As far as
socket.io, realize that
socket.io is a high-level
abstraction over multiple transports (including websockets). The
luvit net module is for basic TCP sockets which are much lower level.
Do you need a duplex (web)socket with the browser, or are just looking
for API examples for a TCP socket?
>
> 2. How to handle with connection broken and reconnect?
> mobile games' networks are not as stable as PC.
> connection broken and reconnect are common. They need taken care.
> but I don't know how to do it.
Yes, I believe there are events emitted when the connection dies. The
unit tests should have some examples, I haven't used the net module
much at all, so I can't speak much for it.
>
> 3. Does it use epoll under linux?
> My lua server will run under linux. I hope it has high performance in net
> io.
> AFAIK, epoll is the best choise under linux to implement async io.
> I don't know what lib luvit uses.
>
Yes, luvit uses libuv which currently uses libev on linux which uses
epoll. libuv uses the best system interface for each platform (IOCP
on windows, kqueue on darwin, epoll on linux...)
> Thank you! you guys rock!
No problem, we've had fun hacking on this. Sorry it's not better
supported. Mostly it's been a hobby of mine and used in production by
a team at Rackspace that already knew both Lua and the Node.JS API.
If anyone else is using luvit seriously, I'd love to hear about it.
-Tim