WiFi Shield - Packet Source Port

I am trying to use WiFi Shield to send some UDP packets to my devices(Ardrone), and the devices will return some UDP packets to Arduino. I need to the source port to get the response.

Is there any way to check Arduino UDP sending packet source port?

It should be the same as the ethernet shield's udp functions. Here is how you get the sender's ip and port so you can send a response packet. I think that is what you are asking.

Thanks for your reply.

I means that if Arduino sends UDP packet from port 32201 (assume), the sender will send response packet back to Arduino port 32201. I have to set Arduino listen from port 32201 to receive response.

You should have to do that before sending the packet.

WiFiUDP.begin(32201);

um… But I don’t know which source port that arduino using to send my UDP packet… And I have to get this information.

Thank you.

This is the Arduino code for starting a socket listening for udp packets. I selected port 8888 for this example. You can use that if you wish.

WiFiUDP Udp;
int localport 8888;

// then in setup() after starting your wifi card
if(!Udp.begin(localport)) Serial.println(F("No socket available"));

Now it will listen for udp packets on port 8888.