Using tcp

Verified
Added by iNTERFACEWARE

Use the net.tcp module to send and receive using tcp sockets

Source Code
   -- send and receive tcp socket data
   
   -- include port as part of hostname
   local s = net.tcp.connect('hostname:8086')
   s:send(Data)
   local Ack = s:recv()
   s:close()
   
   -- specify port separately from host name
   local s = net.tcp.connect{host=hostname, port=8086}
   s:send(Data)
   local Ack = s:recv()
   s:close()
Description
Use the net.tcp module to send and receive using tcp sockets
Usage Details

Examples of using tcp sockets to send and receive data, using net.tcp.send{} and net.tcp.recv{}.

Note: This code does not work “out-of-the-box” you will need to change the hostname to point a valid tcp host first.

How to use the snippet:

  • Paste the code into your script
  • Change the hostname