As the title says... Chat on...

User avatar
By matospaul
#13426 Hello,

I'm having a bit of trouble with the following code:

Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.setmac("\002\001\002\003\003\006")

wifi.sta.config("xxx","yyy")
--tmr.delay(12000000)
--print(wifi.sta.getip())


uart.setup(0,9600,8,0,1,0)
 sv=net.createServer(net.UDP, 3000)
 global_c = nil
 sv:listen(5568, function(c)
     if global_c~=nil then
       global_c:close()
   end
   global_c=c
   c:on("receive",function(sck,pl) uart.write(0,pl) end)
 end)
 
 
 uart.on("data",1, function(data)
  if global_c~=nil then
      global_c:send(data)
  end
 end, 0)


For some reason, I can't establish a UDP connection with this code. However, if I change net.UDP to net.TCP, I can establish a TCP connection and the code works perfectly. Does anyone have any insight as to what I am doing wrong?
User avatar
By cal
#13439 Moin,

I think for UDP you have to register the callback on the socket, not the connection and I don't know
if or when a listen callback is called for UDP.
Code: Select allsv:on("receive",function(sck,pl)
   --uart.write(0,pl)
   print("received: " .. pl)
   end)


Carsten