Mercurial > hg > Members > kono > WifiBroadcast
changeset 13:9bf4bf393e4e
hoge
author | one |
---|---|
date | Sun, 29 Jul 2012 15:55:03 +0900 |
parents | e1f43b669cdb |
children | 7b43c3c60708 |
files | src/wifibroadcast/WifiBroadcastChannel.java |
diffstat | 1 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wifibroadcast/WifiBroadcastChannel.java Sun Jul 29 15:55:03 2012 +0900 @@ -0,0 +1,34 @@ +package wifibroadcast; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardProtocolFamily; +import java.net.StandardSocketOptions; +import java.nio.channels.DatagramChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.spi.SelectorProvider; + +public class WifiBroadcastChannel extends WifiMulticastChannel { + + public WifiBroadcastChannel(int id, int port, SocketType sender) throws IOException { + // join multicast group on this interface, and also use this + // interface for outgoing multicast datagrams + selectMode = false; + selector = SelectorProvider.provider().openSelector(); + + dc = DatagramChannel.open(StandardProtocolFamily.INET) + .setOption(StandardSocketOptions.SO_REUSEADDR, true); + mAddr = WifiBroadcast.getBroadcast(); + sAddr = new InetSocketAddress(mAddr,port); + dc.setOption(StandardSocketOptions.SO_BROADCAST, true); + if (sender == SocketType.Receiver) { + dc.bind(new InetSocketAddress(port)); + if (selectMode) { + dc.configureBlocking(false); + dc.register(selector, SelectionKey.OP_READ); + } + } + } + + +}