MKay Posted January 21, 2017 Posted January 21, 2017 Hello I am currently working on a little application which communicates with dcs. I hooked up a tcp socket in the export lua, which sends every second a a few infos to the application. This works all fine. Now I want to send data from the application to the export.lua and I am stuck. I debugged the application with an external tcp client that communicates with my app and it received the data all fine, its just export.lua which ignores it. Here is a little of my code (step is called on every LuaExportAfterNextFrame): mkay.step = function() local ct = LoGetModelTime(); if(mkay.nextStep <= ct) then mkay.nextStep = ct + 1; local val = list_indication(10); local sp = splitPCNData(val); local s = JSON:encode(sp):gsub("\n","").."\n"; local c1, c2, c3 = mkay.con:send(s) if c1 then else if c3 == 0 then if c2 == "closed" then mkay.fo:write("c2 - ", "\n"); mkay.con = socket.tcp(); mkay.con:settimeout(.01); end mkay.con:connect(mkay.host, mkay.port); mkay.fo:write("c3 - ", "\n"); end end end local line, err = mkay.con:receive(); if err then else mkay.fo:write("received", "\n"); local msg = line; local cmd = string.sub(msg,1,1); if(cmd == "D") then mkay.fo:write(msg, "\n"); local args = StrSplit(string.sub(msg,2),","); local dev = GetDevice(args[1]); if(type(dev) == "table") then dev:performClickableAction(args[2],args[3]); end end end end I log to a file so see whats happening, but I never ever see a "received" in my log. If I do log the error from the receive I get "Timeout" all the time, as an error. This is how I setup the socket. mkay.con = socket.tcp(); mkay.con:settimeout(.01); mkay.con:connect(mkay.host, mkay.port); Any ideas? Thanks, Mkay
MKay Posted January 21, 2017 Author Posted January 21, 2017 Figured it out. The receive method reads all data from the socket until reaching a Line Feed character. So I needed to pass a "\n" at the end of my send message. Works all fine now.
Recommended Posts