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

User avatar
By grytole
#67359 It sounds obvious, but it is not =)

Let we have a UDP server with some SRV_IP that listens on some SRV_PORT.
Client creates UDP socket and sends HELLO on SRV_IP:SRV_PORT from randomly selected port CLI_IP:CLI_PORT.
Server gets HELLO and sends it back to client on CLI_IP:CLI_PORT.

And there is a problem:
How to get response from server?
How client should figure out a port number for listening?
User avatar
By grytole
#67409 Ok, it is obvious.
The socket is same for all operations.
Ensure your device has IP =)

Code: Select allwifi.eventmon.register(wifi.eventmon.STA_GOT_IP, function(unused)
  s = net.createUDPSocket()
  s:on("receive", function(s, response, port, ip)
    myResponseHandler()
  end)
  s:send(port, ip, request)
end)