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

User avatar
By maculan
#14932 Hi,

in my project I created UDP server - when I receive UDP packet from a sender I would like do get info about sender IP address. can somebody advice me how to get this info.

Ma code:
Code: Select all----this is code which establist UDP server on port 10000
UDP_server=net.createServer(net.UDP)
UDP_server:on("receive",function(UDP_server,UDP_RX_packet)
         print("received packet:"..UDP_RX_packet)
         if UDP_RX_packet=="SET 7 ON" --GPIO13
         then
            gpio.write(7, 1)
         end
         if UDP_RX_packet=="SET 7 OFF" --GPIO13
         then
            gpio.write(7, 0)
         end
         if UDP_RX_packet=="REG" --received Registration request
         then
            --how to detect who sent Registration request
         end
end)
UDP_server:listen(10000)
User avatar
By TerryE
#15241 Please don't double post. I am not a moderator so I can't delete your first copy but you can so please do so. There's a option at the top right of your post to do so. At to your Q there are a few undocumented socket methods: sk:getpeer(), sk:hold(), sk:unhold(). The first of these does what you want. //Terry

When in doubt, look at the source.