Socket:accept()
Accept a connection. The socket should have been set to listen for incoming connections with a previous Socket:bind() call.
Return value
Returns one of the following possible values :- Socket, usable to send or recv data from the new connection.
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
-- Echo Server example
local net = require "net"
-- create the server listening Socket
local server = net.Socket("127.0.0.1", 5000)
-- not needed, socket.blocking is already set to true (default)
server.blocking = true
server:listen()
local client = server:accept()
print('Connected with ', client.ip)
-- echo to the client the data just received
while true do
local data = client:recv()
if data == false then
break
end
client:send(data)
end