简体   繁体   中英

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?

只是不要在recvfrom()中指定源地址,然后它将从所有远程地址和端口接收。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM