-->
Page 1 of 2

UDP Server Example

PostPosted: Fri Nov 28, 2014 12:53 pm
by azekie
Hi,

Does any one has a working UDP server example in LUA? I tried the following code, it seems that server starts but UDP messages are not received! note that I'm sending UDP messages to ESP8266 from my Android phone using UDP Sender App which works fine with other UDP servers.

Code: Select allpin=8
port=5000
print("IP:"..wifi.sta.getip()..", Port:"..port)
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
srv=net.createServer(net.UDP)
srv:listen(port,function(conn)
conn:on("receive", function(conn, pl)
   print("Command Reveived")
   if pl=="on" then gpio.write(pin, gpio.HIGH) else gpio.write(pin, gpio.LOW) end
   end)
end)

Re: UDP Server Example

PostPosted: Mon Dec 01, 2014 7:43 am
by alexhi
so it seems UDP server does not work :(

Re: UDP Server Example

PostPosted: Mon Dec 01, 2014 9:14 am
by zeroday
http://www.esp8266.com/viewtopic.php?f=18&t=681

Code: Select alls=net.createServer(net.UDP)
s:on("receive",function(s,c) print(c) end)
s:listen(8888)

Re: UDP Server Example

PostPosted: Mon Dec 01, 2014 10:06 am
by azekie
Thanks, following code is working now:

Code: Select allpin=8
port=5000
print("IP:"..wifi.sta.getip()..", Port:"..port)
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl)
   print("Command Reveived")
   if pl=="on" then gpio.write(pin, gpio.HIGH) else gpio.write(pin, gpio.LOW) end
   end)
srv:listen(port)