I have a project that sends UDP packet on chosen port and on the same port other devices answers with feedback. I am using AsyncUDP to check if there is any packet coming to my port and WiFiUDP to send packets. Problem is while listening, esp s3 is not able to bind socket to the same port, therefore source number for it is random (as always over 50000) and those other devices answer to the same port that the request came. On devices that are using standard esp32 i don't have problem with that (in that case esp is listening and sending from the same port).
This is my code for sending packet.
Code: Select all
WiFiUDP scanUdp;
scanUdp.begin(Network.localIP(), SCAN_PORT);
byte header_buffer[SEARCH_REQUEST_HEADER_SIZE];
memcpy(header_buffer, SEARCH_REQUEST_HEADER, SEARCH_REQUEST_HEADER_SIZE);
if(!scanUdp.beginPacket(IPADDR_BROADCAST, SCAN_PORT)){
DEBUG_PRINTLN(F("Scan request scanUDP.beginPacket returned an error"));
}
scanUdp.write(header_buffer, SEARCH_REQUEST_HEADER_SIZE);
if(!scanUdp.endPacket()){
DEBUG_PRINTLN(F("Scan request scanUDP.endPacket returned error"));
} else {
isScanRequestSend = true;
scanningTime = millis();
}
So my question is: Is it possible to set source port for sending udp packet while listening to this port at the same time or is it possible to somehow get this random source port that esp is setting while unable to bind my port to socket, so I can look for answers on it too?