user1690227
user1690227

Reputation: 1

UDP how to recvfrom different ports at server side with binded port

I have a problem on UDP socket port bind on receiving message from different client ports. I am compiling a C++ utility to check (20K) ports of a Linux server. I create client threads to send different ports of server by pthread_create. At server side, I have to bind socket to certain port, so it can only recvfrom (select like blocked IO)only 1 port. Can you give me some suggestions on UDP server to receive message from different ports?

Upvotes: 0

Views: 1730

Answers (2)

user207421
user207421

Reputation: 311039

Just don't specify a source address in recvfrom(), then it will receive from all remote addresses and ports.

Upvotes: 1

Andy Ross
Andy Ross

Reputation: 12051

If you want to receive packets on multiple ports, you must open multiple sockets and use something like select() to multiplex the I/O. The Berkeley sockets API does not allow a socket to bind() to more than one address.

Upvotes: 0

Related Questions