Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets Lua中的TCP/IP问题_Sockets_Tcp_Lua_Server - Fatal编程技术网

Sockets Lua中的TCP/IP问题

Sockets Lua中的TCP/IP问题,sockets,tcp,lua,server,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 wor

我正在做一个与用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()

我在哪里犯了错误?

您的代码有效:如果我在代码底部添加一个
end
,它对我有效