If the connection has been lost, Socket:recv() returns false and the net.error property returns nil.
Socket:recv([length])
Receive data from the Socket. In blocking mode, the method wait until some data is available for reading.
Parameters
size
An optional integer representing the maximum number of bytes to read from the connection, defaults to 1024.
Return value
Returns one of the following possible values :- Buffer containing the received bytes.
false
if an error occured.- Task object to perform the operation asynchronously if the Socket is non-blocking, returning one of the previous values once finished.
Example
local net = require "net"
-- create a socket to www.google.com on port 80
local socket = net.Socket("www.google.com", 80)
if socket:connect() then
print("Connected to www.google.com !")
socket:send("GET / HTTP/1.1\r\nHost:www.google.com\r\n\r\n")
-- wait to be sure to receive all the data
sleep(300)
print("Data received : "..socket:recv())
end