Hi I'm after a similar function but require a TCP connection to ensure retransmission of any lost packets. Is there an example of a TCP server?
is there anything wrong with this from the lua socket example? can it be improved for the lm?
is there anything wrong with this from the lua socket example? can it be improved for the lm?
Code:
if not server then
-- load namespace
socket = require("socket")
-- create a TCP socket and bind it to the local host, at any port
server = assert(socket.bind("*", 7777))
-- find out which port the OS chose for us
ip, port = server:getsockname()
-- print a message informing what's up
log("Please telnet to localhost on port "..port)
log("After connecting, you have 10s to enter a line to be echoed")
-- loop forever waiting for clients
while 1 do
-- wait for a connection from any client
local client = server:accept()
-- make sure we don't block waiting for this client's line
client:settimeout(10)
-- receive the line
data, err = client:receive()
log(data)
-- done with client, close the object
client:close()
end
end