Mercurial > hg > Members > kono > WifiBroadcast
changeset 18:e9d07562b6b7
network interface
author | one |
---|---|
date | Tue, 31 Jul 2012 16:32:03 +0900 |
parents | 3d71ca942a48 |
children | bb2538b7eb8d |
files | src/wifibroadcast/WifiBroadcastTest.java src/wifibroadcast/WifiMulticastChannel.java |
diffstat | 2 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/wifibroadcast/WifiBroadcastTest.java Tue Jul 31 16:27:50 2012 +0900 +++ b/src/wifibroadcast/WifiBroadcastTest.java Tue Jul 31 16:32:03 2012 +0900 @@ -22,6 +22,7 @@ WifiReceiver wbs[] = new WifiReceiver[sender_count]; private boolean bchannel; private boolean tcp; + private String nis = "en1"; public WifiBroadcastTest() { ports.add(0,DefaultPort); @@ -40,9 +41,9 @@ Thread.sleep(timeout/4); for(int i=0;i<wbs.length;i++) wbs[i] = new WifiMulticast(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Sender); } else if (mchannel) { - for(int i=0;i<wbr.length;i++) wbr[i] = new WifiMulticastChannel(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Receiver); + for(int i=0;i<wbr.length;i++) wbr[i] = new WifiMulticastChannel(i,getAddress(i),getPort(i),nis, WifiReceiver.SocketType.Receiver); Thread.sleep(timeout/4); - for(int i=0;i<wbs.length;i++) wbs[i] = new WifiMulticastChannel(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Sender); + for(int i=0;i<wbs.length;i++) wbs[i] = new WifiMulticastChannel(i,getAddress(i),getPort(i),nis, WifiReceiver.SocketType.Sender); } else if (tcp) { addresses.remove(); addresses.add("127.1"); for(int i=0;i<wbr.length;i++) wbr[i] = new WifiTCP(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Receiver); @@ -86,6 +87,7 @@ case "-c": i++; count = getOptInt(args, count, i); break; case "-t": i++; timeout = getOptInt(args, (int) timeout, i); break; case "-T": i++; testSize = getOptInt(args, testSize, i); break; + case "-n": i++; nis = getOptString(args, nis, i); break; case "-p": i++; setPort(args,i); break; case "-a": i++; setAddress(args, i); break; default: i++; @@ -100,6 +102,7 @@ "-c N send count packet\n"+ "-t N timeout N msec\n"+ "-T N send N byte packet\n"+ + "-n en1 Network Interface name for multicast (default en1)\n"+ "-p N broadcast/multicast port\n"+ "-a S broadcast/multicast address\n"+ "-h print this\n"+
--- a/src/wifibroadcast/WifiMulticastChannel.java Tue Jul 31 16:27:50 2012 +0900 +++ b/src/wifibroadcast/WifiMulticastChannel.java Tue Jul 31 16:32:03 2012 +0900 @@ -23,18 +23,18 @@ public WifiMulticastChannel() {} - public WifiMulticastChannel(int id, String mCASTADDR, int port, SocketType sender) throws IOException { + public WifiMulticastChannel(int id, String mCASTADDR, int port,String nis, SocketType sender) throws IOException { // join multicast group on this interface, and also use this // interface for outgoing multicast datagrams selector = SelectorProvider.provider().openSelector(); - NetworkInterface ni = NetworkInterface.getByName("en1"); + NetworkInterface ni = NetworkInterface.getByName(nis); if (ni==null) { - System.err.println("Can't open network interface "+"en1"); + System.err.println("Can't open network interface "+nis); throw new IOException(); } if (!ni.supportsMulticast()) { - System.err.println("Network interface does not support multicast"+"en1"); + System.err.println("Network interface does not support multicast"+nis); throw new IOException(); }