lua-users home
lua-l archive

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


On 6 August 2011 18:27, Stefan Reich
<stefan.reich.maker.of.eye@googlemail.com> wrote:
> Hi again everyone... this time, a prob with sockets. I am doing this
> on Lua  5.1.4 (stock Lua for Windows), Windows Vista:
>
> sockettest.lua
> ===
>
> require "socket"
> port = 9977
>
> print("Setting up TCP server on port "..tostring(port))
> tcp = socket.tcp()
> status, err = tcp:bind("*", port)
> if not status then
>  print(err)
>  return
> end
> print("TCP server running.")
>
> conn = tcp:accept()
>
>
> And I get:
>
> Setting up TCP server on port 9977
> TCP server running.
> r:\coding\Lua\5.1\lua.exe:
> ...rojects\LuaTest\safelua02\taskmantest\sockettest.lua:19: calling
> 'accept' on bad self (tcp{server} expected, got userdata)
> stack traceback:
>        [C]: in function 'accept'
>        ...rojects\LuaTest\safelua02\taskmantest\sockettest.lua:19: in
> main chunk
>        [C]: ?
>
> What's up with that? Google does not really give me anything when I
> look up the error msg...
>
> Stefan
>
>

look at documentation to the luasocket, esp. the part about tcp [1]
it says:

    socket.tcp()
   Creates and returns a TCP master object. A master object can be
transformed into a server object with the method listen (after a call
to bind) or into a client object with the method connect. The only
other method supported by a master object is the close method.

so you just need to say the master-object `tcp` it's a server.

[1] http://w3.impa.br/~diego/software/luasocket/tcp.html