Before asking my question i'll "briefly" describe what i'm trying to achieve.
I'm making some sort of domotics local network, in which there is a server, 3 to 4 tablets, and many sensors and actuators (like lights, PIR, temperature sensors, watering stations, window blinds, doorbells, etc...)
when you start up the devices they connect to the local server with a fixed IP (only the server has a fixed IP, the rest gets a dynamic one)
and those devices send an introductory packet to present their IP, MAC, task, name and if this device was already connected previously or not and to which slot it was allocated on the server.
after the intruduction is complete they disconnect from the server (close the TCP port) to allow other devices to do the same procedure because the ESP01S i'm using has a maximum number of server connections set to 4.
so at this point, after all the devices presented themselves, i connect one of the tablets to the server and i get a list of all the available devices with their respective IPs...
but here's the tricky part... now i want to send a data packet to a device from the list, so now i have his IP... and i know how to send the data from the tablet... but I just dont know the correct way to open a connection on the receiving device to which any IP can send data.
an alternative would be opening a permanent UDP connection on the receiving device with the server IP, and instead of sending data from the tablet to the device, you would have to send it to the server and then the server must redirect it to the right device trough a new UDP connection.
on another note, by testing some stuff, i found that if you open let's say and UDP connection with a random IP, you can get UDP data packets even from other IPs... but i don't believe this is the right way to go because of the unknown issues that may arise, example (ACTUAL OUTPUT):
device_1:
AT+CIFSR
+CIFSR:STAIP,"192.168.1.16"
+CIFSR:STAMAC,"50:02:91:da:5a:a8"
OK
AT+CIPSTART="UDP","192.168.1.15",8000,8001
CONNECT
OK
AT+CIPSEND=5
OK
busy s...
Recv 5 bytes
SEND OK
device_2:
AT+CIFSR
+CIFSR:STAIP,"192.168.1.15"
+CIFSR:STAMAC,"50:02:91:da:5b:4a"
OK
AT+CIPSTART="UDP","192.168.1.100",8001,8000
CONNECT
OK
+IPD,5:TEST
from the example above i opened an UPD connection with IP 192.168.1.100, but got data from IP 192.168.1.16... what is that about?