If I comment out the part starting with async.setTimeout then it will return the value as intended. Also if I comment out client.close() in ondata then it will work as well.
The intention is to return the value as soon as possible, but if the server takes too long then return nil on timeout. I would think this is a fairly common scenario? Is this not the right way to do it?
I have the following code for the TCP server (modified from the example) in a file named
tcp-server.lua
.I have the following for a function that retrieves the message sent by the server.
I ran
th tcp-server.lua
in one terminal and then callingget_msg()
in a th shell (in another process). The result isIf I comment out the part starting with
async.setTimeout
then it will return the value as intended. Also if I comment outclient.close()
inondata
then it will work as well.The intention is to return the value as soon as possible, but if the server takes too long then return nil on timeout. I would think this is a fairly common scenario? Is this not the right way to do it?