Mercurial > hg > Members > kono > WifiBroadcast
changeset 24:b801551b7d49
add test files
author | Taninari YU <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 07 Aug 2013 16:31:39 +0900 |
parents | 280de47f460d |
children | a17e8b4ffe75 |
files | src/wifibroadcast/WifiBroadcast.java src/wifibroadcast/WifiBroadcastTest.java |
diffstat | 2 files changed, 54 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/wifibroadcast/WifiBroadcast.java Tue Jul 31 17:41:29 2012 +0900 +++ b/src/wifibroadcast/WifiBroadcast.java Wed Aug 07 16:31:39 2013 +0900 @@ -27,8 +27,8 @@ System.out.println("Found broadcast "+address0); mAddr = address0; s = new DatagramSocket(); - s.bind(new InetSocketAddress(address0,port+1+id)); - s.setBroadcast(true); +// s.bind(new InetSocketAddress(address0,port+1+id)); +// s.setBroadcast(true); } catch (SocketException e) { } } else { @@ -51,9 +51,24 @@ public void send(ByteBuffer testData) throws IOException { - DatagramPacket sendPacket = new DatagramPacket(testData.array(), testData.limit(),mAddr, port); - s.send(sendPacket); - testData.position(testData.limit()); + if(testData.limit() < 1500) { + DatagramPacket sendPacket = new DatagramPacket(testData.array(), testData.limit(),mAddr, port); + s.send(sendPacket); + testData.position(testData.limit()); + } else { + int temp = 1000; + for(int i = 0 ; i < testData.limit();) { + DatagramPacket sendPacket = new DatagramPacket(testData.array(),i, temp, mAddr, port); + s.send(sendPacket); + testData.position(i); + i += 1000; + if(testData.limit() - i > 1000) { + temp = 1000; + } else { + temp = testData.limit() - i; + } + } + } System.out.println("send"); }
--- a/src/wifibroadcast/WifiBroadcastTest.java Tue Jul 31 17:41:29 2012 +0900 +++ b/src/wifibroadcast/WifiBroadcastTest.java Wed Aug 07 16:31:39 2013 +0900 @@ -1,7 +1,11 @@ package wifibroadcast; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; import java.util.LinkedList; public class WifiBroadcastTest { @@ -188,7 +192,8 @@ @Override public void run() { - ByteBuffer testData = getTestData(testSize); +// ByteBuffer testData = getTestData(testSize); + ByteBuffer testData = readTestData(); int i = 0; try { Thread.sleep(timeout); @@ -233,7 +238,7 @@ ByteBuffer testData = ByteBuffer.allocate(4096); int bad = 0, good = 0; try { - for(int i = 0; running && i<count;i++) { + for(int i = 0; running && i<count;i++) { testData.clear(); wbr.recieve(testData,timeout); if (!testData.hasRemaining()) continue; @@ -266,4 +271,31 @@ b.flip(); return b; } + + public ByteBuffer readTestData() { + FileChannel srcChannel = null; + String path = "./testfile.txt"; + ByteBuffer buffer = null; + try { + srcChannel = fileReader(path).getChannel(); + buffer = ByteBuffer.allocate((int) srcChannel.size()); + srcChannel.read(buffer); + buffer.clear(); + return buffer; + } catch (IOException e) { + System.out.println("File not found."); + } finally { + try { + srcChannel.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return buffer; + } + + private FileInputStream fileReader(String path) + throws FileNotFoundException { + return new FileInputStream(new File(path)); + } }