Lua中的TCP / IP问题

时间:2016-05-08 19:13:55

标签: sockets tcp lua server

我正在做一个与用Lua语言创建TCP / IP通信相关的项目。我的电脑将成为服务器,我想将它与另一台电脑连接。

所以,这是代码:

local socket = require'socket'
local server = socket.tcp()
server:bind('*', 7200)
server:listen(32)
>>>>local client = server:accept() 
--Here I have a problem. It is not working. 
--It says:
--calling 'accept' on bad self (tcp{server} expected,got userdata in function)
client:settimeout(10)
 -- receive the line
 local line, err = client:receive()
  -- if there was no error, send it back to the client
 if not err then 
 client:send('test') --end
  -- done with client, close the object
  client:close()

我在哪里弄错了?

1 个答案:

答案 0 :(得分:0)

您的代码有效:如果我在代码底部添加end,则对我有用。