# HG changeset patch # User oshiro # Date 1543397319 -32400 # Node ID 12633f67f3cf046c0b0809ac8b18c861fe41e945 # Parent 42ecbd9364fa3fee3de56c095cddf492d2a93e8a jar diff -r 42ecbd9364fa -r 12633f67f3cf .idea/encodings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/encodings.xml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf .idea/gradle.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/gradle.xml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf .idea/libraries/Gradle__junit_junit_4_12.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__junit_junit_4_12.xml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf .idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf .idea/modules/oshiro.oshiro.iml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/modules/oshiro.oshiro.iml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf .idea/modules/oshiro.oshiro.main.iml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/modules/oshiro.oshiro.main.iml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf .idea/modules/oshiro.oshiro.test.iml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/modules/oshiro.oshiro.test.iml Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 42ecbd9364fa -r 12633f67f3cf build.gradle --- a/build.gradle Wed Nov 28 17:34:23 2018 +0900 +++ b/build.gradle Wed Nov 28 18:28:39 2018 +0900 @@ -1,106 +1,37 @@ - -apply plugin:'java' - - -sourceCompatibility = 1.11 -targetCompatibility = 1.11 -version = '0.1.0' +plugins { + id 'java' +} -project.ext.baseName = 'wifibroadcast' - -defaultTasks 'clean', 'dist' +group 'FileWrite' +version '1.0-SNAPSHOT' - - - +sourceCompatibility = 11 -def manifestAttributes = ['Main-Class': 'jp.ac.uryukyu.ie.kono.wifibroadcast.WifiBroadcast', - 'Implementation-Version': "${project.version} (${buildNo})", - 'Implementation-Title': 'WifiBroadcast', - 'Implementation-Vendor': 'uryukyu'] +repositories { + mavenCentral() + jcenter() +} -jar { - baseName = project.baseName - version = null - manifest { - attributes manifestAttributes - } - def runtimeDeps = configurations.viewerSwingRuntime.collect { - it.isDirectory() ? it : zipTree(it) - } - from(runtimeDeps) { - exclude 'META-INF/**' +test { + useJUnitPlatform { + includeEngines 'junit-jupiter' } } - - - -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 +dependencies { + testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.1.0' + testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.1.0' } -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}" +compileJava { + options.compilerArgs << "-Werror" +} +jar { + from configurations.compile.collect { it.isDirectory() ? it :zipTree(it) } + manifest { + attributes "Main-Class":"jp.ac.uryukyu.ie.kono.wifibroadcast.WifiBroadcastTest" + attributes 'Implementation-Title':'Gradle Quickstart', 'Implementation-Version':version } - 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' +defaultTasks 'test' diff -r 42ecbd9364fa -r 12633f67f3cf pom.xml --- a/pom.xml Wed Nov 28 17:34:23 2018 +0900 +++ b/pom.xml Wed Nov 28 18:28:39 2018 +0900 @@ -20,7 +20,7 @@ - wifibroadcast.WifiBroadcastTest + WifiBroadcastTest diff -r 42ecbd9364fa -r 12633f67f3cf src/main/java/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcast.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcast.java Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,103 @@ +package jp.ac.uryukyu.ie.kono.wifibroadcast; + +import java.net.NetworkInterface; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +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 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) { + } + + +} diff -r 42ecbd9364fa -r 12633f67f3cf src/main/java/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastChannel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastChannel.java Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,31 @@ +package jp.ac.uryukyu.ie.kono.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); + } + } + } + + +} diff -r 42ecbd9364fa -r 12633f67f3cf src/main/java/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastTest.java Wed Nov 28 18:28:39 2018 +0900 @@ -0,0 +1,301 @@ +package jp.ac.uryukyu.ie.kono.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 ports = new LinkedList(); + LinkedList addresses = new LinkedList(); + 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;i0) { + 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 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 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) { - } - - -} diff -r 42ecbd9364fa -r 12633f67f3cf src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastChannel.java --- a/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastChannel.java Wed Nov 28 17:34:23 2018 +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); - } - } - } - - -} diff -r 42ecbd9364fa -r 12633f67f3cf src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastTest.java --- a/src/main/jp/ac/uryukyu/ie/kono/wifibroadcast/WifiBroadcastTest.java Wed Nov 28 17:34:23 2018 +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 ports = new LinkedList(); - LinkedList addresses = new LinkedList(); - 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;i0) { - 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