Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
some newbie questions about luvit
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
丁树凯  
View profile  
 More options Sep 25 2012, 9:17 am
From: 丁树凯 <dingshu...@gmail.com>
Date: Tue, 25 Sep 2012 06:17:38 -0700 (PDT)
Local: Tues, Sep 25 2012 9:17 am
Subject: some newbie questions about luvit

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.

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 ..

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.

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.

Thank you!  you guys rock!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Caswell  
View profile  
 More options Sep 25 2012, 10:28 am
From: Tim Caswell <t...@creationix.com>
Date: Tue, 25 Sep 2012 09:28:53 -0500
Local: Tues, Sep 25 2012 10:28 am
Subject: Re: some newbie questions about luvit

On Tue, Sep 25, 2012 at 8:17 AM, 丁树凯 <dingshu...@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!

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Caswell  
View profile  
 More options Sep 25 2012, 11:33 am
From: Tim Caswell <t...@creationix.com>
Date: Tue, 25 Sep 2012 10:33:25 -0500
Local: Tues, Sep 25 2012 11:33 am
Subject: Re: some newbie questions about luvit
I should mention that I'm playing with a new API style called
continuables. <https://github.com/luvit/continuable/blob/master/continuable.lua>

In this new API, a readable stream is any lua table that has a
:read(callback) method.  The callback gets (err, chunk).  A writable
stream is any table with a :write(chunk, callback) method.

Making a TCP echo server using the continuable module would look like:

    local tcp = require('continuable').tcp

    local server = tcp.createServer("0.0.0.0", 3000, function (socket)
      local onRead, onWrite
      socket:write("Welcome\n")()
      onRead = function (err, chunk)
        if err then error(err) end
        socket:write(chunk)(onWrite)

        -- If there was data, then read again
        if chunk then
          socket:read()(onRead)
        end
      end
      onWrite = function (err)
        if err then error(err) end
      end
      socket:read()(onRead)
    end)
    print("Echo server listening on port " .. tcp.getsockname(server).port)

Or using coroutines and await sugar:

    local tcp = require('continuable').tcp
    local newFiber = require('continuable').fiber.new
    local await = require('continuable').fiber.await

    local server = tcp.createServer("0.0.0.0", 3000, function (socket)
      newFiber(function ()
        socket:write("Welcome\n")()
        repeat
          local chunk = await(socket:read())
          socket:write(chunk)()
        until not chunk
      end)(function (err)
        error(err)
      end)
    end)
    print("Echo server listening on port " .. tcp.getsockname(server).port)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vladimir Dronnikov  
View profile  
 More options Sep 25 2012, 1:57 pm
From: Vladimir Dronnikov <dronni...@gmail.com>
Date: Tue, 25 Sep 2012 21:57:07 +0400
Local: Tues, Sep 25 2012 1:57 pm
Subject: Re: some newbie questions about luvit

coro sugar looks really sweet. but it needs to be under heavy load test,
really. say, piping a few hundreds of Mb file. i recall new web/static
segfaulted such load.
25.09.2012 19:33 пользователь "Tim Caswell" <t...@creationix.com> написал:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Caswell  
View profile  
 More options Sep 25 2012, 2:13 pm
From: Tim Caswell <t...@creationix.com>
Date: Tue, 25 Sep 2012 13:13:12 -0500
Local: Tues, Sep 25 2012 2:13 pm
Subject: Re: some newbie questions about luvit
correction, :read(callback) should be :read()(callback) and
:write(chunk, callback) should be :write(chunk)(callback).  It's
correct in the sample code, just not the paragraph above it.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »