Mercurial > hg > Members > kono > WifiBroadcast
comparison src/wifibroadcast/WifiMulticastChannel.java @ 15:cce76e5eb29b
with tcp
author | one |
---|---|
date | Tue, 31 Jul 2012 16:18:26 +0900 |
parents | 7b43c3c60708 |
children | 3d71ca942a48 |
comparison
equal
deleted
inserted
replaced
14:7b43c3c60708 | 15:cce76e5eb29b |
---|---|
17 protected InetAddress mAddr; | 17 protected InetAddress mAddr; |
18 protected DatagramChannel dc; | 18 protected DatagramChannel dc; |
19 protected SocketAddress sAddr; | 19 protected SocketAddress sAddr; |
20 // select on DatagramChannel does not work now | 20 // select on DatagramChannel does not work now |
21 protected Selector selector; | 21 protected Selector selector; |
22 protected boolean selectMode = false; | 22 protected boolean selectMode = true; |
23 | 23 |
24 public WifiMulticastChannel() {} | 24 public WifiMulticastChannel() {} |
25 | 25 |
26 public WifiMulticastChannel(int id, String mCASTADDR, int port, SocketType sender) throws IOException { | 26 public WifiMulticastChannel(int id, String mCASTADDR, int port, SocketType sender) throws IOException { |
27 // join multicast group on this interface, and also use this | 27 // join multicast group on this interface, and also use this |
36 if (!ni.supportsMulticast()) { | 36 if (!ni.supportsMulticast()) { |
37 System.err.println("Network interface does not support multicast"+"en1"); | 37 System.err.println("Network interface does not support multicast"+"en1"); |
38 throw new IOException(); | 38 throw new IOException(); |
39 } | 39 } |
40 | 40 |
41 dc = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET); | 41 // dc = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET); |
42 dc = DatagramChannel.open(StandardProtocolFamily.INET); | |
42 dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); | 43 dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); |
43 dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); | 44 dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); |
44 mAddr = InetAddress.getByName(mCASTADDR); | 45 mAddr = InetAddress.getByName(mCASTADDR); |
45 sAddr = new InetSocketAddress(mAddr,port); | 46 sAddr = new InetSocketAddress(mAddr,port); |
46 dc.join(mAddr, ni); | 47 dc.join(mAddr, ni); |