shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
I actually meant the port from which the ESP32 can send messages through UDP.
"the port from which the esp32 can send through UDP"
this is the port of the requested client then - name it "LOCALPORT"
this port is usually a randomly free thing
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
The port you guys are mentioning is the port of the UDP server (on my computer for instance).
right, the port of the responder part which is listening on this port for incomming messages - name it "SERVERPORT"
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
I'm actually looking for the port I can combine with the IP address of the ESP32 to send messages from my computer to the ESP32 and this doesn't seem to be the one in the config.
you want send from your PC ( client ) to the ESP32 ( server - listening on a specific fixed port )
how many ESP32 do you have in your setup? do you want talk from PC to an other ESP32 which is listening
or do you want send from your PC ( Server ) to the ESP32 ( client ) back/reply to the requested packt /request ?
so only want send back messages to a client which was connected as Client the PC which act s a server?
if you want connect to a responder - the responder should listening on a specific port which you are setup for listening and acting
all clients should know this port for connecting and it is a fix port then which you setup like it is talked -
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
From my tests, it seems it is randomly generated.
you sure mean the client sending port ( request port ) - this is randimly generated as long you not fix this in your setup too.
it is a code thing, but you can set this also to a fixed port - not sure why you want do this, you get allways the remotly port which was connecting to the host in the message, so if you want send back, you simple send to the "sockets.client.port" which you see in your PC protokoll.
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
I wait for the ESP32 to send me a packet
...now you have the senders port
it does not have to do with the senders target port, which you setup
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
and there in the packet i can see esp32 IP address and incoming port.
incoming port = request port = randomly as long as you not set it fix in your code at socket setup.
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
I can use then that incoming port to reply to the esp32 but it's not systemic.
if you want send an ACK this request.client.port is then usefull.
if you want talk between esp32 and pc or many esp.. you can setup every as a UDP "server" on the same port..
all "servers" listening now on same port but have difference IP's.
you can talk to one over the specific IP then -
if you want talk to one of them simple use the specific IP then.
if you want talk with all, simple send message to all of them in a broadcast.
shirogeek wrote: ↑Fri Oct 15, 2021 11:02 am
I hope my question is clearer now.
it was from begin
but i think the answeres goes now trivial
do you use arduino or ESP-IDF or other?
how many clients you have in the setup? ( PC - ESP32 )
which programming software / language you use on PC side?
edit:
arduino example
what you search for is likewise this for your PC:
// Send return packet
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(reply);
UDP.endPacket();
and you want know how you can setup your ESP so - that the PC allways has the right ESP port to connect them
you can setup your ESP as an Server ecample? Or you can set your ESP client port as static so it is not more randomly -
so pricipal you transform then the client to an server with this, which is not listening but use allways the same
request port in sending packet's. it is not a good idea. better you setup then the esp as an server i think.
as long as you not close the socket, the requested port is valid.
so you can talk between your pc and your ESP as long as you not close the socket.connection over this port right?