Socket:connect()method
Connect to the remote Socket.ip address. Used in blocking mode, the methods wait until the connection is established, or returns immediately otherwise.
Return value
trueif the operation succedded, orfalseif 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
--! luart-extensions
import 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 header data
sleep(300)
local nbytes = socket:peek()
print("Length of header: "..nbytes)
print("Length of data received : "..#socket:recv())
end