Mavlink reading with android custom app via hotspot

Hi,

Using datagramSocket and listening to mavlink on port 14552, I have successfully retrieved mavlink messages with a custom app on the herelink, and am able to select the information I want.
I now needto do the same on another android device connected on the Herelink wifi hotspot, as a Qgrouncontrol or MissionPlanner(android version) do (automatically connecting to port 14550, I assume using UDP).
I, however,do not manage to do the same on my custom app, the “datagramsocket.receive(packet)” command keeps throwing “ECONNREFUSED (Connection refused)” error when the socket is connected to “localhost:14550” . I am using android studio.

Did someone managed to do this, or knows how it is implemanted on Qgroundcontrol / mission Planner?

bind to udp port 14551 if running on herelink

I did manage to do it running on Herelink itself
but not when running on another android device (acting as second screen with position of the drone on a map) connected to the herelink hotspot
The same code that works on herelink throws “connection refused” when receiving mavlink packets via hotspot on this second device

from an external device, use the herelink IP and port 14550, again bind to 14550

Thanks Michael, it resolved it…!
My problem was thinking I had to connect to the port, not bind, and I bound to a random port when creating the socket… binding the socket to port 14550 using herelink IP solved it.
Thank you!