[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question: Nonblocking accept() always returning non nil value?
- From: Daniel Quintela <danielq@...>
- Date: Sun, 20 Jun 2004 12:32:12 -0300
Hi:
I tested your code with a fresh copy of LuaSocket 2.0Beta and it works ok:
F:\tmp\luasocket-2.0-beta-win32>lua olle.lua
Binding to host '127.0.0.1' and port 8070...
Waiting packets on 127.0.0.1:8070...
Trying to accept conn 06/20/04 12:27:26
---> nil timeout
Trying to accept conn 06/20/04 12:27:27
---> nil timeout
Trying to accept conn 06/20/04 12:27:28
---> nil timeout
Trying to accept conn 06/20/04 12:27:29
---> tcp{client}: 00414F70 nil
accept
Client connected
Echoing kajhsdkjashd from 127.0.0.1:8070
Echoing 821681762381 from 127.0.0.1:8070
Client closed connection
Are you trying with the beta version or the alfa version ?
Regards,
Daniel
----- Original Message -----
From: "Olle Persson" <ollep8934@hotmail.com>
To: <lua-l@lua.org>
Sent: Saturday, June 19, 2004 9:13 AM
Subject: Question: Nonblocking accept() always returning non nil value?
>
> Hello everyone!
>
> New LUA user here so please bear with me =)
> I have a problem with luasocket 2.0 that I cant solve. Have tried
searching
> the archive but havent found anything useful yet. Im trying to start a TCP
> socket in nonblocking mode using settimeout(1) and then accept().
According
> to Luasocket2.0 reference:
>
> server:accept()
> ===============
> ...
> If a connection is successfully initiated, a client
> object is returned. If a timeout condition is met,
> the method returns nil followed by the error string
> 'timeout'.
> ...
>
> So after accept() returns I check the first return value. If its not nil I
> have a client connected, right? Well it seems to always return a non nil
> value even though its got no incoming client!? Also tried checking the
> second argument for "timeout" string but this also failed. This is driving
> me nuts and Im positive its something simple that I have just missed. Any
> suggestions are appreciated =) Heres the code:
>
>
>
>
> --
>
***************************************************************************
> host = host or "127.0.0.1"
> port = port or 8070
> if arg then
> host = arg[1] or host
> port = arg[2] or port
> end
> print("Binding to host '" ..host.. "' and port " ..port.. "...")
> server, err = socket.bind(host, port)
> assert(server, err)
> server:settimeout(1)
> ip, port = server:getsockname()
> assert(ip, port)
> print("Waiting packets on " .. ip .. ":" .. port .. "...")
>
> while 1 do
> print("Trying to accept conn " .. os.date())
> csess, status = server:accept()
>
> if csess then
> print("accept")
> break
> end
> end
>
> print("Client connected")
> while 1 do
> data, err = csess:receive("*l")
> if err then
> print("Client closed connection")
> os.exit()
> end
> if data then
> print("Echoing " .. data .. " from " .. ip .. ":" .. port)
> csess:send(data)
> end
> end
> --
>
***************************************************************************
>
>
> This script can be started without parameters.
> Was gonna test client using "telnet localhost 8070".
>
>
>
> /Bor
>
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>