Does Java NIO support broadcast or multicast?

2019-05-15 20:18发布

I am searching if Java NIO implements broadcast. I need to create a peer that sends messages to other peers, using multicast or broadcast. I was searching in the API 1.6, but I don't find anything in the DatagramChannel class.

Thanks in advance.

3条回答
虎瘦雄心在
2楼-- · 2019-05-15 20:51

NIO2 supports multicast, that's in Java 7.

http://javanio.info/filearea/nioserver/WhatsNewNIO2.pdf

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-05-15 20:55

Before NIO2 you have to make use of all kinds of hacks to make a datagram channel join a multicast group. Not sure how they could have left multicast channels out of NIO1.

查看更多
迷人小祖宗
4楼-- · 2019-05-15 21:08

You don't need to use NIO for this, java.net.MulticastSocket supports this directly.

But, to completely answer your question, no. You cannot use a DatagramChannel because you cannot tell it what socket to use, and there is nothing else even close to what you would need in NIO.

查看更多
登录 后发表回答