Reputation: 248
I am trying to create TCP client in lua
local host, port = HOST, PORT
local socket = require("socket")
client = socket.tcp();
client:connect(host, port);
client:send("Hello User");
this works fine but when i add
while true do
local s, status, partial = client:receive()
print(s or partial)
if status == "closed" then break end
end
to read data from socket it block total execution of code.
Upvotes: 2
Views: 1548
Reputation: 26744
By default, all luasocket I/O operations are blocking. You need to use socket.settimeout(0)
(settimeout) to disable blocking. You can then check for "timeout" value returned as status and act accordingly.
Depending on how the data is being sent, this answer may be relevant as well.
Upvotes: 1