# HG changeset patch # User one # Date 1343544903 -32400 # Node ID 9bf4bf393e4e4f5561a9a1fbb9a82123ec84870d # Parent e1f43b669cdb5fad9f523ec4a9edf359c79ae580 hoge diff -r e1f43b669cdb -r 9bf4bf393e4e src/wifibroadcast/WifiBroadcastChannel.java --- /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); + } + } + } + + +}