简体   繁体   中英

How to poll multiple sockets on java client side?

I've got a question with my program about Java socket communication. On client side, I need to listen to port 1900 and get the UDP message sent out by another software. Then I need to send the UDP message to Server side through port 1901 and listen to server's response.

At the same time,I still need to listen to local port 1900.That is as soon as something occurs on port 1900 and 1901, I need to deal with it. In a word,on client side,I need to monitor port 1900 as well as 1901,and once one of them gets something asynchronously,I need to come to fix it. I think it requires knowledge of Java NIO, but I don't know it exactly. Thank you for advice.

You can use

ServerSocketChannel to do that I think, though I have not yet tried to do the same. You can see this stackoverflow thread for more information.

Java Server - Multiple ports

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