0

I have been using the code example given in

How to read the UDP data payload coming from a port using C program

for reading udp data from the 5000 port.

However in my machine this port is used by another process and I know it. What I want to know is a solution to keep the c code receiving data from the port even if it is used from the other process.

Thank you guy for your help.

C. DAVID
  • 61
  • 1
  • 7

1 Answers1

3

No, basically you cannot open a UDP port which was used by another process already, unless all the sockets bound to and to bind to the same port has option SO_REUSEPORT set.

Whithout SO_REUSEPORT option being set, your second binding to the used port will fail with error code being EINVAL, See manual of bind(2)

EINVAL The socket is already bound to an address.

For option SO_REUSEPORT, you can refer to this post in SO.

Yingyu YOU
  • 369
  • 1
  • 5