lua-users home
lua-l archive

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



On 08/06/2008, at 5:08 PM, Diego Nehab wrote:

LuaSocket uses recv/send instead of read/write. The posix
manual says they are equivalent if no flags are used, which
is LuaSocket's case. On Windows, however, this will never
work.

Hi Diego,

Thanks for responding. :)

I didn't really expect it to work on Windows, as they tend to fudge things around a bit regarding sockets/files, however I had more hope under Linux.

My code for reading from the socket, in my C program, was:

  // check for input on our socket

    if (FD_ISSET (s, &in_set))
      {
      int nRead;

      nRead = read (s, buf, sizeof(buf) - 1)

  // and process buf ...


And for the keyboard:

    // check for input on the keyboard

    if (FD_ISSET (STDIN_FILENO, &in_set))
      {
      int nRead;

      nRead = read (STDIN_FILENO, buf, sizeof(buf) - 1);

So basically it was the same, and it worked (I think) regardless of how much you typed. Maybe the keyboard buffered a line, but then you only got the "select" notification when something was there.



On the other hand, stdin is probably set to blocking mode,
so when there is nothing available, it recv will block until
all the data you need shows up. Also, keyboard input will be
buffered until you hit return, I guess.


In my C program I don't think I turned blocking off at all.

If you really want to use keyboard:receive(), you have to
call setfd on a *connected* socket. The socket returned by
socket.tcp() does not support the receive method.

Ah, you mean make some sort of dummy connection, and then switch FDs? How would that work?

----

Just out of curiosity, is there some sort of limit on simultaneous connections? I am writing a stress-test application using luasocket, to test out a MUD server. Despite it successfully making 200 connections with no asserts, only 65 players ever seem to be active. It is almost as if only the first 65 ever get reported by select. But maybe it is a server-side problem. Just asking in case you say "oh yes, we limited it to 65 connections".

- Nick