Mercurial > hg > Members > kono > WifiBroadcast
changeset 26:42ecbd9364fa
gradle
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.gradle Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,106 @@ + +apply plugin:'java' + + +sourceCompatibility = 1.11 +targetCompatibility = 1.11 +version = '0.1.0' + +project.ext.baseName = 'wifibroadcast' + +defaultTasks 'clean', 'dist' + + + + + +def manifestAttributes = ['Main-Class': 'jp.ac.uryukyu.ie.kono.wifibroadcast.WifiBroadcast', + 'Implementation-Version': "${project.version} (${buildNo})", + 'Implementation-Title': 'WifiBroadcast', + 'Implementation-Vendor': 'uryukyu'] + +jar { + baseName = project.baseName + version = null + manifest { + attributes manifestAttributes + } + def runtimeDeps = configurations.viewerSwingRuntime.collect { + it.isDirectory() ? it : zipTree(it) + } + from(runtimeDeps) { + exclude 'META-INF/**' + } +} + + + + +task noSshJar (type: Jar, dependsOn: classes) { + baseName = 'nossh/' + project.baseName + version = null + manifest { + attributes manifestAttributes + } + from sourceSets.main.output +} + +artifacts { + archives file('src/web/viewer-applet-example.html') + archives noSshJar +} + +uploadArchives { + repositories { + + } + uploadDescriptor = false +} + +task dist(dependsOn: uploadArchives) + +def processBuildNo(currentVersion) { + final String VERSION = 'version' + final String BUILD = 'build' + + def lastVersion = currentVersion + def lastBuild = 0 + def buildNoFile = new File('.build_no') + if ( ! buildNoFile.exists()) { + buildNoFile.createNewFile() + buildNoFile << "${VERSION}=${lastVersion}\n${BUILD}=${lastBuild}" + } + def versions = [:] + buildNoFile.eachLine { + def splitted = it.split('=') + if (splitted.size() == 2) { + def (key, value) = splitted + switch(key.trim()) { + case VERSION: + lastVersion = value.trim() + break + case BUILD: + try { + lastBuild = value != null ? value.trim() as Integer : 0 + } catch (NumberFormatException) {} + versions[lastVersion] = lastBuild + break + } + } + } + lastVersion = versions[currentVersion] + if (null == lastVersion) { + versions[currentVersion] = 0 + } + ++versions[currentVersion] + def outString = '' + versions.each { v, b -> + outString += "${VERSION}=${v}\n${BUILD}=${b}\n\n" + } + buildNoFile.write(outString) + versions[currentVersion] +} + +// set mainclass to Application Plugin +mainClassName = 'com.glavsoft.viewer.TreeViewer' +applicationName = 'TreeVNC'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcast.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,104 @@ +package wifibroadcast; + +import java.net.NetworkInterface; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.InterfaceAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.util.Enumeration; + +public class WifiBroadcast implements WifiReceiver { + + private DatagramSocket s; + private int port; + private InetAddress mAddr; + + public WifiBroadcast(int id,int port, SocketType sender) throws IOException { + this.port = port; + + if (sender == SocketType.Sender) { + try { + InetAddress address0 = getBroadcast(); + System.out.println("Found broadcast "+address0); + mAddr = address0; + s = new DatagramSocket(); +// s.bind(new InetSocketAddress(address0,port+1+id)); +// s.setBroadcast(true); + } catch (SocketException e) { + } + } else { + // InetAddress address0 = getBroadcast(); + s = new DatagramSocket(port); + // s.bind(new InetSocketAddress(address0,port)); + s.setReuseAddress(true); + s.setBroadcast(true); + } + } + + public void recieve(ByteBuffer testData, long timeout) throws IOException { + DatagramPacket packet = new DatagramPacket(testData.array(),testData.capacity()); + s.receive(packet); + testData.limit(packet.getLength()); + testData.position(0); + System.out.println("recv "+packet.getLength()+" bytes from "+packet.getAddress()); + return; // one at a time + } + + + public void send(ByteBuffer testData) throws IOException { + 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"); + } + + public InetAddress getBroadcast0() throws UnknownHostException { + return InetAddress.getByName("192.168.100.66"); + } + + public static InetAddress getBroadcast() throws SocketException { + Enumeration<NetworkInterface> interfaces = + NetworkInterface.getNetworkInterfaces(); + while (interfaces.hasMoreElements()) { + NetworkInterface networkInterface = interfaces.nextElement(); + if (networkInterface.isLoopback()) + continue; // Don't want to broadcast to the loopback interface + for (InterfaceAddress interfaceAddress : + networkInterface.getInterfaceAddresses()) { + InetAddress broadcast = interfaceAddress.getBroadcast(); + if (broadcast == null) + continue; + // Use the address + System.out.println("MTU="+networkInterface.getMTU()); + return broadcast; + } + } + throw new SocketException(); + } + + @Override + public void selectMode(boolean mode) { + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastChannel.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,31 @@ +package wifibroadcast; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardProtocolFamily; +import java.net.StandardSocketOptions; +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 + selector = SelectorProvider.provider().openSelector(); + dc = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET); + dc.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); + } + } + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastTest.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,301 @@ +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 { + private static int DefaultPort = 8412; + private static String MCASTADDR = "224.0.0.1"; + private static int testSize = 256; + private static long timeout = 1000; + + + LinkedList<Integer> ports = new LinkedList<Integer>(); + LinkedList<String> addresses = new LinkedList<String>(); + int count = 16; + boolean multicast = false; + boolean mchannel = false; + int receiver_count = 1; + int sender_count = 1; + WifiReceiver wbr[] = new WifiReceiver[receiver_count]; + WifiReceiver wbs[] = new WifiReceiver[sender_count]; + private boolean bchannel; + private boolean tcp; + private String nis = "en1"; + private boolean selectMode = false; + private int portIndex = 0; + private int addressIndex = 0; + + public WifiBroadcastTest() { + ports.add(0,DefaultPort); + addresses.add(0,MCASTADDR); + } + + public static void main(String args[]) { + new WifiBroadcastTest().test(args); + } + + public void test(String args[]) { + options(args); + try { + if (multicast) { + for(int i=0;i<wbr.length;i++) wbr[i] = new WifiMulticast(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Receiver); + 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),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),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); + Thread.sleep(timeout/4); + for(int i=0;i<wbs.length;i++) wbs[i] = new WifiTCP(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Sender); + } else if (bchannel) { + for(int i=0;i<wbr.length;i++) wbr[i] = new WifiBroadcastChannel(i,getPort(i),WifiReceiver.SocketType.Receiver); + Thread.sleep(timeout/4); + for(int i=0;i<wbs.length;i++) wbs[i] = new WifiBroadcastChannel(i,getPort(i),WifiReceiver.SocketType.Sender); + } else { + for(int i=0;i<wbr.length;i++) wbr[i] = new WifiBroadcast(i,getPort(i),WifiReceiver.SocketType.Receiver); + Thread.sleep(timeout/4); + for(int i=0;i<wbs.length;i++) wbs[i] = new WifiBroadcast(i,getPort(i),WifiReceiver.SocketType.Sender); + } + } catch (IOException e) { + System.err.println("err "+e); + } catch (InterruptedException e) { + System.err.println("err "+e); + } + runTest(count, wbr, wbs); + + } + + private String getAddress(int i) { + return addresses.get(i%addresses.size()); + } + + private int getPort(int i) { + return ports.get(i%ports.size()); + } + + public void options(String[] args) { + for(int i=0;i<args.length;i++) { + switch(args[i]) { + case "-m": multicast = true; break; + case "-channel": mchannel = true; break; + case "-bchannel": bchannel = true; break; + case "-tcp": tcp = true; break; + case "-r": i++; receiver_count = getOptInt(args, receiver_count, i); wbr = new WifiReceiver[receiver_count]; break; + case "-s": i++; sender_count = getOptInt(args, sender_count, i); wbs = new WifiReceiver[sender_count]; break; + 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; + case "-select": i++; selectMode = true; break; + default: i++; + System.out.println( + "(default) Broadcast DatagramSocket\n"+ + "-m Multicast DatagramSocket\n"+ + "-cahnnel Multicast with DatagramChannel\n"+ + "-bcahnnel Broadcase with DatagramChannel\n"+ + "-tcp TCP stream\n"+ + "-r N create N receivers\n"+ + "-s N create N senders\n"+ + "-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"+ + "-select use select for timeout\n"+ + "-h print this\n"+ + "" + ); + return; + } + } + } + + + + + public void runTest(int count, WifiReceiver[] wbr, WifiReceiver wbs[]) { + Thread t = timeouter(); + Thread send[] = new Thread[wbs.length]; + int id = 0; + for(WifiReceiver s:wbs) { + send[id]= sender(s,count); + id ++; + } + id = 0; + Thread recv[] = new Thread[wbr.length]; + for(WifiReceiver r: wbr) { + recv[id] = receiver(r,id, count, timeout); + id ++; + } + try { + for(int i = 0;i<wbr.length;i++) { + recv[i].join(); + } + for(int i = 0;i<wbs.length;i++) { + send[i].join(); + } + t.join(); + } catch (InterruptedException e) { + } + } + + + + public int getOptInt(String[] args, int count, int i) { + if (i<args.length) { count = Integer.parseInt(args[i]); } + return count; + } + + public String getOptString(String[] args, String str, int i) { + if (i<args.length) { str = args[i]; } + return str; + } + + private void setAddress(String[] args, int i) { + String adr = getOptString(args,addresses.get(0),i); + int p; + if ((p=adr.indexOf(":"))>0) { + String sp = adr.substring(p+1); + adr = adr.substring(0,p-1); + portIndex = addressIndex; + if (ports.size()>portIndex) ports.remove(portIndex); + ports.add(portIndex,Integer.parseInt(sp)); + portIndex ++; + } + if (addresses.size()>addressIndex) addresses.remove(addressIndex); + addresses.add(addressIndex,adr); + addressIndex++; + } + + private void setPort(String[] args, int i) { + String sport = getOptString(args,"0", i); + if (ports.size()>portIndex) ports.remove(portIndex); + ports.add(portIndex,Integer.parseInt(sport)); + portIndex++; + } + + public Thread sender(final WifiReceiver wbs, final int count) { + wbs.selectMode(selectMode); + Runnable sender = new Runnable() { + + @Override + public void run() { +// ByteBuffer testData = getTestData(testSize); + ByteBuffer testData = readTestData(); + int i = 0; + try { + Thread.sleep(timeout); + for(i = 0; i<count;i++) { + testData.putInt(0, i); + wbs.send(testData); + testData.flip(); + } + } catch (Exception e) { + System.err.println("sender error at "+i+" "+e); + } + } + }; + Thread s = new Thread(sender); + s.start(); + return s; + } + + private boolean running; + + public Thread timeouter() { + running = true; + Runnable timeouter = new Runnable() { + @Override + public void run() { + try { + Thread.sleep(30*1000); + } catch (InterruptedException e) { + } + running = false; + } + }; + Thread t = new Thread(timeouter); t.start(); + return t; + } + + public Thread receiver(final WifiReceiver wbr, final int id, final int count, final long timeout) { + wbr.selectMode(selectMode); + Runnable receiver = new Runnable() { + @Override + public void run() { + ByteBuffer testData = ByteBuffer.allocate(4096); + int bad = 0, good = 0; + try { + for(int i = 0; running && i<count;i++) { + testData.clear(); + wbr.recieve(testData,timeout); + if (!testData.hasRemaining()) continue; + System.out.println("receive id"+id+":"+testData.remaining()+" bytes."); + int seq = testData.getInt(); + if (seq!=i) { + bad++; i = seq; + } else { + good++; + } + } + } catch (Exception e) { + System.err.println("receiver error "+e); + } + System.out.println("get "+good+" packets, "+bad+" losts."); + } + }; + Thread r = new Thread(receiver); r.start(); + return r; + } + + public ByteBuffer getTestData(int i) { + ByteBuffer b = ByteBuffer.allocate(i); + b.putInt(0); + for(int j = 0; j<256; j++ ) { + b.put((byte)j); + if (! b.hasRemaining()) break; + if (j == 255) j=0; + } + 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)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiDatagram.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,67 @@ +package wifibroadcast; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; + +public class WifiDatagram implements WifiReceiver { + /** + * Test class for non broadcast/multicast datagram + */ + + private DatagramSocket s; + private int port; + private InetAddress mAddr; + + public WifiDatagram(int id, int port, SocketType sender) throws IOException { + this.port = port; + + if (sender == SocketType.Sender) { + try { + InetAddress address0 = getLocalAddress(); + System.out.println("Found broadcast "+address0); + mAddr = address0; + s = new DatagramSocket(); + s.bind(new InetSocketAddress(address0,port+1)); + s.setBroadcast(true); + } catch (SocketException e) { + } + } else { + // InetAddress address0 = getBroadcast(); + s = new DatagramSocket(port); + // s.bind(new InetSocketAddress(address0,port)); + s.setReuseAddress(true); + s.setBroadcast(true); + } + } + + public void recieve(ByteBuffer testData, long timeout) throws IOException { + DatagramPacket packet = new DatagramPacket(testData.array(),testData.capacity()); + s.receive(packet); + testData.limit(packet.getLength()); + testData.position(0); + return; // one at a time + } + + + public void send(ByteBuffer testData) throws IOException { + DatagramPacket sendPacket = new DatagramPacket(testData.array(), testData.limit(),mAddr, port); + s.send(sendPacket); + testData.position(testData.limit()); + System.out.println("send"); + } + + public InetAddress getLocalAddress() throws UnknownHostException { + return InetAddress.getByName("127.0.0.1"); + } + + @Override + public void selectMode(boolean mode) { + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiMulticast.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,46 @@ +package wifibroadcast; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +public class WifiMulticast implements WifiReceiver { + private MulticastSocket soc; + private InetAddress mAddr; + private int port; + + public WifiMulticast(int id, String mCASTADDR, int port, SocketType sender) throws IOException { + this.port = port; + try { + mAddr = InetAddress.getByName(mCASTADDR); + soc = new MulticastSocket(port); + soc.joinGroup(mAddr); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void recieve(ByteBuffer testData, long timeout) throws IOException { + DatagramPacket packet = new DatagramPacket(testData.array(),testData.capacity()); + soc.receive(packet); + testData.limit(packet.getLength()); + testData.position(0); + } + + @Override + public void send(ByteBuffer testData) throws IOException { + DatagramPacket sendPacket = new DatagramPacket(testData.array(), testData.limit(),mAddr, port); + soc.send(sendPacket); + testData.position(testData.limit()); + } + + @Override + public void selectMode(boolean mode) { + + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiMulticastChannel.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,86 @@ +package wifibroadcast; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.NetworkInterface; +import java.net.SocketAddress; +import java.net.StandardProtocolFamily; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.DatagramChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.spi.SelectorProvider; + +public class WifiMulticastChannel implements WifiReceiver { + protected InetAddress mAddr; + protected DatagramChannel dc; + protected SocketAddress sAddr; + // select on DatagramChannel does not work now + protected Selector selector; + protected boolean selectMode = false; + + public WifiMulticastChannel() {} + + 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(nis); + if (ni==null) { + System.err.println("Can't open network interface "+nis); + throw new IOException(); + } + + if (!ni.supportsMulticast()) { + System.err.println("Network interface does not support multicast"+nis); + throw new IOException(); + } + + // dc = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET); + dc = DatagramChannel.open(StandardProtocolFamily.INET); + dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); + dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); + mAddr = InetAddress.getByName(mCASTADDR); + sAddr = new InetSocketAddress(mAddr,port); + dc.join(mAddr, ni); + + if (sender == SocketType.Receiver) { + dc.bind(new InetSocketAddress(port)); + if (selectMode) { + dc.configureBlocking(false); + dc.register(selector, SelectionKey.OP_READ); + } + } + } + + @Override + public void recieve(ByteBuffer testData, long timeout) throws IOException { + if (selectMode && selector.select(timeout)==0) { + System.out.println("bad select "+timeout); + testData.limit(0); testData.position(0); + return; + } + SocketAddress s = dc.receive(testData); + testData.flip(); + System.out.println("From "+s+" "+testData.remaining()+" bytes."); + } + + @Override + public void send(ByteBuffer testData) throws IOException { + while(testData.hasRemaining()) { + dc.send(testData, sAddr); + } +// try { +// Thread.sleep(100); +// } catch (InterruptedException e) { +// } + } + + @Override + public void selectMode(boolean mode) { + selectMode = mode; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiReceiver.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,17 @@ +package wifibroadcast; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public interface WifiReceiver { + + public enum SocketType {Sender , Receiver } ; + + void recieve(ByteBuffer testData, long timeout) throws IOException; + + void send(ByteBuffer testData) throws IOException; + + void selectMode(boolean mode); + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiTCP.java Wed Nov 28 17:34:23 2018 +0900 @@ -0,0 +1,80 @@ +package wifibroadcast; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.nio.channels.spi.SelectorProvider; + +public class WifiTCP implements WifiReceiver { + protected InetAddress mAddr; + protected SocketAddress sAddr; + // select on DatagramChannel does not work now + protected static Selector selector; + protected boolean selectMode = false; + private SocketChannel sc; + private static ServerSocketChannel ss; + + static { + try { + ss = SelectorProvider.provider().openServerSocketChannel(); + selector = SelectorProvider.provider().openSelector(); + } catch (IOException e) { + } + } + public WifiTCP() {} + + public WifiTCP(int id, String mCASTADDR, int port, SocketType sender) throws IOException { + mAddr = InetAddress.getByName(mCASTADDR); + sAddr = new InetSocketAddress(mAddr,port); + if (sender == SocketType.Receiver) { + ss.setOption(StandardSocketOptions.SO_REUSEADDR, true); + ss.bind(new InetSocketAddress(port)); + } else { + sc = SelectorProvider.provider().openSocketChannel(); + sc.connect(sAddr); + } + } + + @Override + public void recieve(ByteBuffer testData, long timeout) throws IOException { + if (sc==null) { + sc = ss.accept(); + if (selectMode) { + sc.configureBlocking(false); + sc.register(selector, SelectionKey.OP_READ); + } + } + if (selectMode && selector.select(timeout)==0) { + System.out.println("bad select "+timeout); + testData.limit(0); testData.position(0); + return; + } + sc.read(testData); + testData.flip(); + System.out.println("Read "+testData.remaining()+" bytes."); + } + + @Override + public void send(ByteBuffer testData) throws IOException { + while(testData.hasRemaining()) { + sc.write(testData); + } +// try { +// Thread.sleep(100); +// } catch (InterruptedException e) { +// } + } + + @Override + public void selectMode(boolean mode) { + selectMode = mode; + } + +}
--- a/src/wifibroadcast/WifiBroadcast.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -package wifibroadcast; - -import java.net.NetworkInterface; -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.InterfaceAddress; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.util.Enumeration; - -public class WifiBroadcast implements WifiReceiver { - - private DatagramSocket s; - private int port; - private InetAddress mAddr; - - public WifiBroadcast(int id,int port, SocketType sender) throws IOException { - this.port = port; - - if (sender == SocketType.Sender) { - try { - InetAddress address0 = getBroadcast(); - System.out.println("Found broadcast "+address0); - mAddr = address0; - s = new DatagramSocket(); -// s.bind(new InetSocketAddress(address0,port+1+id)); -// s.setBroadcast(true); - } catch (SocketException e) { - } - } else { - // InetAddress address0 = getBroadcast(); - s = new DatagramSocket(port); - // s.bind(new InetSocketAddress(address0,port)); - s.setReuseAddress(true); - s.setBroadcast(true); - } - } - - public void recieve(ByteBuffer testData, long timeout) throws IOException { - DatagramPacket packet = new DatagramPacket(testData.array(),testData.capacity()); - s.receive(packet); - testData.limit(packet.getLength()); - testData.position(0); - System.out.println("recv "+packet.getLength()+" bytes from "+packet.getAddress()); - return; // one at a time - } - - - public void send(ByteBuffer testData) throws IOException { - 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"); - } - - public InetAddress getBroadcast0() throws UnknownHostException { - return InetAddress.getByName("192.168.100.66"); - } - - public static InetAddress getBroadcast() throws SocketException { - Enumeration<NetworkInterface> interfaces = - NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) { - NetworkInterface networkInterface = interfaces.nextElement(); - if (networkInterface.isLoopback()) - continue; // Don't want to broadcast to the loopback interface - for (InterfaceAddress interfaceAddress : - networkInterface.getInterfaceAddresses()) { - InetAddress broadcast = interfaceAddress.getBroadcast(); - if (broadcast == null) - continue; - // Use the address - System.out.println("MTU="+networkInterface.getMTU()); - return broadcast; - } - } - throw new SocketException(); - } - - @Override - public void selectMode(boolean mode) { - } - - -}
--- a/src/wifibroadcast/WifiBroadcastChannel.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package wifibroadcast; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.StandardProtocolFamily; -import java.net.StandardSocketOptions; -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 - selector = SelectorProvider.provider().openSelector(); - dc = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET); - dc.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); - } - } - } - - -}
--- a/src/wifibroadcast/WifiBroadcastTest.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,301 +0,0 @@ -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 { - private static int DefaultPort = 8412; - private static String MCASTADDR = "224.0.0.1"; - private static int testSize = 256; - private static long timeout = 1000; - - - LinkedList<Integer> ports = new LinkedList<Integer>(); - LinkedList<String> addresses = new LinkedList<String>(); - int count = 16; - boolean multicast = false; - boolean mchannel = false; - int receiver_count = 1; - int sender_count = 1; - WifiReceiver wbr[] = new WifiReceiver[receiver_count]; - WifiReceiver wbs[] = new WifiReceiver[sender_count]; - private boolean bchannel; - private boolean tcp; - private String nis = "en1"; - private boolean selectMode = false; - private int portIndex = 0; - private int addressIndex = 0; - - public WifiBroadcastTest() { - ports.add(0,DefaultPort); - addresses.add(0,MCASTADDR); - } - - public static void main(String args[]) { - new WifiBroadcastTest().test(args); - } - - public void test(String args[]) { - options(args); - try { - if (multicast) { - for(int i=0;i<wbr.length;i++) wbr[i] = new WifiMulticast(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Receiver); - 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),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),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); - Thread.sleep(timeout/4); - for(int i=0;i<wbs.length;i++) wbs[i] = new WifiTCP(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Sender); - } else if (bchannel) { - for(int i=0;i<wbr.length;i++) wbr[i] = new WifiBroadcastChannel(i,getPort(i),WifiReceiver.SocketType.Receiver); - Thread.sleep(timeout/4); - for(int i=0;i<wbs.length;i++) wbs[i] = new WifiBroadcastChannel(i,getPort(i),WifiReceiver.SocketType.Sender); - } else { - for(int i=0;i<wbr.length;i++) wbr[i] = new WifiBroadcast(i,getPort(i),WifiReceiver.SocketType.Receiver); - Thread.sleep(timeout/4); - for(int i=0;i<wbs.length;i++) wbs[i] = new WifiBroadcast(i,getPort(i),WifiReceiver.SocketType.Sender); - } - } catch (IOException e) { - System.err.println("err "+e); - } catch (InterruptedException e) { - System.err.println("err "+e); - } - runTest(count, wbr, wbs); - - } - - private String getAddress(int i) { - return addresses.get(i%addresses.size()); - } - - private int getPort(int i) { - return ports.get(i%ports.size()); - } - - public void options(String[] args) { - for(int i=0;i<args.length;i++) { - switch(args[i]) { - case "-m": multicast = true; break; - case "-channel": mchannel = true; break; - case "-bchannel": bchannel = true; break; - case "-tcp": tcp = true; break; - case "-r": i++; receiver_count = getOptInt(args, receiver_count, i); wbr = new WifiReceiver[receiver_count]; break; - case "-s": i++; sender_count = getOptInt(args, sender_count, i); wbs = new WifiReceiver[sender_count]; break; - 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; - case "-select": i++; selectMode = true; break; - default: i++; - System.out.println( - "(default) Broadcast DatagramSocket\n"+ - "-m Multicast DatagramSocket\n"+ - "-cahnnel Multicast with DatagramChannel\n"+ - "-bcahnnel Broadcase with DatagramChannel\n"+ - "-tcp TCP stream\n"+ - "-r N create N receivers\n"+ - "-s N create N senders\n"+ - "-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"+ - "-select use select for timeout\n"+ - "-h print this\n"+ - "" - ); - return; - } - } - } - - - - - public void runTest(int count, WifiReceiver[] wbr, WifiReceiver wbs[]) { - Thread t = timeouter(); - Thread send[] = new Thread[wbs.length]; - int id = 0; - for(WifiReceiver s:wbs) { - send[id]= sender(s,count); - id ++; - } - id = 0; - Thread recv[] = new Thread[wbr.length]; - for(WifiReceiver r: wbr) { - recv[id] = receiver(r,id, count, timeout); - id ++; - } - try { - for(int i = 0;i<wbr.length;i++) { - recv[i].join(); - } - for(int i = 0;i<wbs.length;i++) { - send[i].join(); - } - t.join(); - } catch (InterruptedException e) { - } - } - - - - public int getOptInt(String[] args, int count, int i) { - if (i<args.length) { count = Integer.parseInt(args[i]); } - return count; - } - - public String getOptString(String[] args, String str, int i) { - if (i<args.length) { str = args[i]; } - return str; - } - - private void setAddress(String[] args, int i) { - String adr = getOptString(args,addresses.get(0),i); - int p; - if ((p=adr.indexOf(":"))>0) { - String sp = adr.substring(p+1); - adr = adr.substring(0,p-1); - portIndex = addressIndex; - if (ports.size()>portIndex) ports.remove(portIndex); - ports.add(portIndex,Integer.parseInt(sp)); - portIndex ++; - } - if (addresses.size()>addressIndex) addresses.remove(addressIndex); - addresses.add(addressIndex,adr); - addressIndex++; - } - - private void setPort(String[] args, int i) { - String sport = getOptString(args,"0", i); - if (ports.size()>portIndex) ports.remove(portIndex); - ports.add(portIndex,Integer.parseInt(sport)); - portIndex++; - } - - public Thread sender(final WifiReceiver wbs, final int count) { - wbs.selectMode(selectMode); - Runnable sender = new Runnable() { - - @Override - public void run() { -// ByteBuffer testData = getTestData(testSize); - ByteBuffer testData = readTestData(); - int i = 0; - try { - Thread.sleep(timeout); - for(i = 0; i<count;i++) { - testData.putInt(0, i); - wbs.send(testData); - testData.flip(); - } - } catch (Exception e) { - System.err.println("sender error at "+i+" "+e); - } - } - }; - Thread s = new Thread(sender); - s.start(); - return s; - } - - private boolean running; - - public Thread timeouter() { - running = true; - Runnable timeouter = new Runnable() { - @Override - public void run() { - try { - Thread.sleep(30*1000); - } catch (InterruptedException e) { - } - running = false; - } - }; - Thread t = new Thread(timeouter); t.start(); - return t; - } - - public Thread receiver(final WifiReceiver wbr, final int id, final int count, final long timeout) { - wbr.selectMode(selectMode); - Runnable receiver = new Runnable() { - @Override - public void run() { - ByteBuffer testData = ByteBuffer.allocate(4096); - int bad = 0, good = 0; - try { - for(int i = 0; running && i<count;i++) { - testData.clear(); - wbr.recieve(testData,timeout); - if (!testData.hasRemaining()) continue; - System.out.println("receive id"+id+":"+testData.remaining()+" bytes."); - int seq = testData.getInt(); - if (seq!=i) { - bad++; i = seq; - } else { - good++; - } - } - } catch (Exception e) { - System.err.println("receiver error "+e); - } - System.out.println("get "+good+" packets, "+bad+" losts."); - } - }; - Thread r = new Thread(receiver); r.start(); - return r; - } - - public ByteBuffer getTestData(int i) { - ByteBuffer b = ByteBuffer.allocate(i); - b.putInt(0); - for(int j = 0; j<256; j++ ) { - b.put((byte)j); - if (! b.hasRemaining()) break; - if (j == 255) j=0; - } - 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)); - } -}
--- a/src/wifibroadcast/WifiDatagram.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -package wifibroadcast; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; - -public class WifiDatagram implements WifiReceiver { - /** - * Test class for non broadcast/multicast datagram - */ - - private DatagramSocket s; - private int port; - private InetAddress mAddr; - - public WifiDatagram(int id, int port, SocketType sender) throws IOException { - this.port = port; - - if (sender == SocketType.Sender) { - try { - InetAddress address0 = getLocalAddress(); - System.out.println("Found broadcast "+address0); - mAddr = address0; - s = new DatagramSocket(); - s.bind(new InetSocketAddress(address0,port+1)); - s.setBroadcast(true); - } catch (SocketException e) { - } - } else { - // InetAddress address0 = getBroadcast(); - s = new DatagramSocket(port); - // s.bind(new InetSocketAddress(address0,port)); - s.setReuseAddress(true); - s.setBroadcast(true); - } - } - - public void recieve(ByteBuffer testData, long timeout) throws IOException { - DatagramPacket packet = new DatagramPacket(testData.array(),testData.capacity()); - s.receive(packet); - testData.limit(packet.getLength()); - testData.position(0); - return; // one at a time - } - - - public void send(ByteBuffer testData) throws IOException { - DatagramPacket sendPacket = new DatagramPacket(testData.array(), testData.limit(),mAddr, port); - s.send(sendPacket); - testData.position(testData.limit()); - System.out.println("send"); - } - - public InetAddress getLocalAddress() throws UnknownHostException { - return InetAddress.getByName("127.0.0.1"); - } - - @Override - public void selectMode(boolean mode) { - } - -}
--- a/src/wifibroadcast/WifiMulticast.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -package wifibroadcast; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; - -public class WifiMulticast implements WifiReceiver { - private MulticastSocket soc; - private InetAddress mAddr; - private int port; - - public WifiMulticast(int id, String mCASTADDR, int port, SocketType sender) throws IOException { - this.port = port; - try { - mAddr = InetAddress.getByName(mCASTADDR); - soc = new MulticastSocket(port); - soc.joinGroup(mAddr); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void recieve(ByteBuffer testData, long timeout) throws IOException { - DatagramPacket packet = new DatagramPacket(testData.array(),testData.capacity()); - soc.receive(packet); - testData.limit(packet.getLength()); - testData.position(0); - } - - @Override - public void send(ByteBuffer testData) throws IOException { - DatagramPacket sendPacket = new DatagramPacket(testData.array(), testData.limit(),mAddr, port); - soc.send(sendPacket); - testData.position(testData.limit()); - } - - @Override - public void selectMode(boolean mode) { - - } - -} -
--- a/src/wifibroadcast/WifiMulticastChannel.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -package wifibroadcast; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.NetworkInterface; -import java.net.SocketAddress; -import java.net.StandardProtocolFamily; -import java.net.StandardSocketOptions; -import java.nio.ByteBuffer; -import java.nio.channels.DatagramChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.spi.SelectorProvider; - -public class WifiMulticastChannel implements WifiReceiver { - protected InetAddress mAddr; - protected DatagramChannel dc; - protected SocketAddress sAddr; - // select on DatagramChannel does not work now - protected Selector selector; - protected boolean selectMode = false; - - public WifiMulticastChannel() {} - - 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(nis); - if (ni==null) { - System.err.println("Can't open network interface "+nis); - throw new IOException(); - } - - if (!ni.supportsMulticast()) { - System.err.println("Network interface does not support multicast"+nis); - throw new IOException(); - } - - // dc = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET); - dc = DatagramChannel.open(StandardProtocolFamily.INET); - dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); - dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); - mAddr = InetAddress.getByName(mCASTADDR); - sAddr = new InetSocketAddress(mAddr,port); - dc.join(mAddr, ni); - - if (sender == SocketType.Receiver) { - dc.bind(new InetSocketAddress(port)); - if (selectMode) { - dc.configureBlocking(false); - dc.register(selector, SelectionKey.OP_READ); - } - } - } - - @Override - public void recieve(ByteBuffer testData, long timeout) throws IOException { - if (selectMode && selector.select(timeout)==0) { - System.out.println("bad select "+timeout); - testData.limit(0); testData.position(0); - return; - } - SocketAddress s = dc.receive(testData); - testData.flip(); - System.out.println("From "+s+" "+testData.remaining()+" bytes."); - } - - @Override - public void send(ByteBuffer testData) throws IOException { - while(testData.hasRemaining()) { - dc.send(testData, sAddr); - } -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// } - } - - @Override - public void selectMode(boolean mode) { - selectMode = mode; - } - -}
--- a/src/wifibroadcast/WifiReceiver.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package wifibroadcast; - -import java.io.IOException; -import java.nio.ByteBuffer; - -public interface WifiReceiver { - - public enum SocketType {Sender , Receiver } ; - - void recieve(ByteBuffer testData, long timeout) throws IOException; - - void send(ByteBuffer testData) throws IOException; - - void selectMode(boolean mode); - - -}
--- a/src/wifibroadcast/WifiTCP.java Wed Aug 07 16:33:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -package wifibroadcast; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.StandardSocketOptions; -import java.nio.ByteBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.SelectorProvider; - -public class WifiTCP implements WifiReceiver { - protected InetAddress mAddr; - protected SocketAddress sAddr; - // select on DatagramChannel does not work now - protected static Selector selector; - protected boolean selectMode = false; - private SocketChannel sc; - private static ServerSocketChannel ss; - - static { - try { - ss = SelectorProvider.provider().openServerSocketChannel(); - selector = SelectorProvider.provider().openSelector(); - } catch (IOException e) { - } - } - public WifiTCP() {} - - public WifiTCP(int id, String mCASTADDR, int port, SocketType sender) throws IOException { - mAddr = InetAddress.getByName(mCASTADDR); - sAddr = new InetSocketAddress(mAddr,port); - if (sender == SocketType.Receiver) { - ss.setOption(StandardSocketOptions.SO_REUSEADDR, true); - ss.bind(new InetSocketAddress(port)); - } else { - sc = SelectorProvider.provider().openSocketChannel(); - sc.connect(sAddr); - } - } - - @Override - public void recieve(ByteBuffer testData, long timeout) throws IOException { - if (sc==null) { - sc = ss.accept(); - if (selectMode) { - sc.configureBlocking(false); - sc.register(selector, SelectionKey.OP_READ); - } - } - if (selectMode && selector.select(timeout)==0) { - System.out.println("bad select "+timeout); - testData.limit(0); testData.position(0); - return; - } - sc.read(testData); - testData.flip(); - System.out.println("Read "+testData.remaining()+" bytes."); - } - - @Override - public void send(ByteBuffer testData) throws IOException { - while(testData.hasRemaining()) { - sc.write(testData); - } -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// } - } - - @Override - public void selectMode(boolean mode) { - selectMode = mode; - } - -}