Mercurial > hg > Members > kono > WifiBroadcast
changeset 5:7679d10bdae9
multiple receivers
author | one |
---|---|
date | Sat, 28 Jul 2012 19:51:55 +0900 |
parents | 404778ac3f55 |
children | 248ae478dbe6 |
files | src/wifibroadcast/WifiBroadcastTest.java |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/wifibroadcast/WifiBroadcastTest.java Sat Jul 28 19:33:34 2012 +0900 +++ b/src/wifibroadcast/WifiBroadcastTest.java Sat Jul 28 19:51:55 2012 +0900 @@ -14,26 +14,28 @@ int count = 16; boolean multicast = false; boolean mchannel = false; - WifiReceiver wbr = null; + int receiver_count = 1; + WifiReceiver wbr[] = new WifiReceiver[receiver_count]; WifiReceiver wbs = null; for(int i=0;i<args.length;i++) { if (args[i].equals("-m")) multicast = true; else if (args[i].equals("-channel")) mchannel = true; + else if (args[i].equals("-r")) { i++; receiver_count = getOptInt(args, count, i); wbr = new WifiReceiver[receiver_count]; } else if (args[i].equals("-c")) { i++; count = getOptInt(args, count, i);} else if (args[i].equals("-t")) { i++; timeout = getOptInt(args, count, i);} else if (args[i].equals("-p")) { i++; port = getOptInt(args, count, i);} } try { if (multicast) { - wbr = new WifiMulticast(MCASTADDR,port,WifiReceiver.SocketType.Receiver); + for(int i=0;i<wbr.length;i++) wbr[i] = new WifiMulticast(MCASTADDR,port,WifiReceiver.SocketType.Receiver); Thread.sleep(timeout); wbs = new WifiMulticast(MCASTADDR,port,WifiReceiver.SocketType.Receiver); } else if (mchannel) { - wbr = new WifiMulticastChannel(MCASTADDR,port,WifiReceiver.SocketType.Receiver); + for(int i=0;i<wbr.length;i++) wbr[i]= new WifiMulticastChannel(MCASTADDR,port,WifiReceiver.SocketType.Receiver); Thread.sleep(timeout); wbs = new WifiMulticastChannel(MCASTADDR,port,WifiReceiver.SocketType.Sender); } else { - wbr = new WifiBroadcast(port,WifiReceiver.SocketType.Receiver); + for(int i=0;i<wbr.length;i++) wbr[i]= new WifiBroadcast(port,WifiReceiver.SocketType.Receiver); Thread.sleep(timeout); wbs = new WifiBroadcast(port,WifiReceiver.SocketType.Sender); } @@ -43,7 +45,10 @@ System.err.println("err "+e); } sender(wbs,count); - receiver(wbr,count, timeout); + int id = 0; + for(WifiReceiver r: wbr) { + receiver(r,id++, count, timeout); + } } @@ -84,7 +89,7 @@ private static boolean running; - public static void receiver(final WifiReceiver wbr, final int count, final long timeout) { + public static void receiver(final WifiReceiver wbr, final int id, final int count, final long timeout) { running = true; Runnable timeouter = new Runnable() { @Override @@ -106,7 +111,7 @@ testData.clear(); wbr.recieve(testData,timeout); if (!testData.hasRemaining()) continue; - System.out.println("receive "+testData.remaining()+" bytes."); + System.out.println("receive id"+id+":"+testData.remaining()+" bytes."); int seq = testData.getInt(); if (seq!=i) { bad++; i = seq;