This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Receive UDP string
#7
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?

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
Reply


Messages In This Thread
Receive UDP string - by leonidas - 24.08.2017, 13:16
RE: Receive UDP string - by admin - 24.08.2017, 17:51
RE: Receive UDP string - by AlexLV - 24.08.2017, 22:47
RE: Receive UDP string - by leonidas - 28.08.2017, 05:25
RE: Receive UDP string - by admin - 28.08.2017, 08:54
RE: Receive UDP string - by AlexLV - 04.09.2017, 08:41
RE: Receive UDP string - by Diggerz - 15.02.2021, 01:38
RE: Receive UDP string - by admin - 15.02.2021, 07:46
RE: Receive UDP string - by Diggerz - 18.02.2021, 08:56
RE: Receive UDP string - by admin - 18.02.2021, 08:58

Forum Jump: