Following post provides a TCP client opening a socket towards 192.168.14.100 port 56789.
Beware the PC or laptop you test against has its firewall allow the traffic to this IP and port.
Beware as well when posting back a reply from the server end, that the below sample is reading received data upon reception of line feed trigger ("*l"), meaning the tool or app on the server side must send the LF character otherwise it will not be displaid on the AAF studio console.
local sched = require "sched" -- Lua scheduling and synchronization lib.
local socket = require "socket"
function main ()
local my_socket = socket.tcp()
my_socket:connect("192.168.14.100", 56789)
if my_socket then
-- send
my_socket:send("This is data sent from the AAF TCP client socket")
-- receive
while true
do
local data = assert(my_socket:receive("*l"))
-- there are 3 methods to receive data:
-- "*l", to receive line by line (beware that the client must send the line feed character! if you are using a TCP client tool, do check the "LineFeed" box if any)
-- n, to specify a number of bytes to read out from the socket
-- "*a", to read all the data on the fly.
if data then
print("Received: ", data)
end
end
else print ("error upon socket creation: ", my_socket)
end
end
--------------------------------------------------------------------------------
-- Schedule the main function, and launch the scheduler main loop
sched.run(main)
sched.loop()