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.

copas connecting to tcp server cannot receive percentage
#1
Hi,

Ok so I have a resident script using a copas udp server on the localhost to receive commands from knx objects (event script) , then there is a copas tcp client connecting to an tcp server on the local network. I did it this way so they don't block each other.  The issue I am experiencing is that when the tcp server sends out an percentage character the tcp client stops receiving anything else from the server.

Does someone have an idea?

Thanks,

Roger

Code:
if not ready then
 socket = require("socket")
 copas = require("copas")
 alert('not Ready')
 ready=true
 
 function parse(data)
   alert('parsing...  '..data)
 end
   
 function fromKNX(command)
  alert('from KNX.. '..command)
 end
 
 local server = socket.udp()
 server:setsockname("127.0.0.1",23456)
 function handler(skts)
   skts = copas.wrap(skts)
   alert("UDP connection handler")
   while true do
     local s, err
     alert("UDP receiving...")
     s, erro = skts:receive(2048)
     if not s then
       alert("UDP Receive error: ", erro)
       break
     end
     alert("Received data, bytes: "..s)
     fromKNX(s)
   end
 end
 copas.addserver(server, handler, 1)  
end

if not skt then
 alert('not socket')
 if skt then
   skt:close()
   skt = nil
 end
 -- create tcp client
 skt, err = socket.connect('10.10.10.41', 4999)
 skt:settimeout(0)
 copas.addthread(function()
     while true do
      local resp,err = copas.receive(skt)
       if not resp then
         alert("TCP Receive error: ", err)
         break
       end
       parse(resp)
     end
   end)
 -- connect ok, reset buffer
 if skt then
   alert('[tcp-client] connection ok')
   warningfailed = true
   init()
   -- error while connecting,
 else
   if warningfailed then alert('[tcp-client] connection failed (conn): %s', err) end
   warningfailed = false
 end  
end

copas.loop()
Reply
#2
Default receive behaviour is to read a single so it will not return until a new line ("\n") character is found in the buffer. Are you sure the server is sending it correctly?
Reply
#3
Hi Admin,

Yes, I am testing with the hercules tcp server. for example, i send

1234
12345%

and I don't see 12345% as a alert.

If I then restart the script and send %% then I receive a single % in the alert and then I can continue sending from the tcp server and the client resident script continues to alert the received data.

Thanks,

Roger

You can get the hercules app from http://www.hw-group.com/products/hercules/index_en.html
Reply
#4
Alert behaves like string.format and if you pass 12345% it will result in an error. This will be fixed in RC4. For now, just change alert to log.
Reply
#5
Hi,

So I changed the copas.addthread function.


Code:
 copas.addthread(function()
     while true do
      local resp,err = copas.receive(skt,'*l')
       if not resp then
         alert("Jandy Receive error: ", err)
         copas.removeserver(skt)
         skt = nil          
         break
       end
       parse(resp)
     end
   end)




Now when I send % I see in the alerts
there was an error/usr/share/lua/genohm-scada.lua:0: bad argument #2 to 'format' (no value)

Any ideas?

Thanks,


Roger
Reply
#6
Code:
function parse(data)
  alert('parsing: %s', data)
end
Reply
#7
Ok, wow... so everything was blocking because the alert statement couldn't concatenate the string?


Big thanks Admin


Thanks,


Roger
Reply


Forum Jump: