Mercurial > hg > Members > kono > WifiBroadcast
changeset 16:b5ab7003f6d1
tcp running
author | one |
---|---|
date | Tue, 31 Jul 2012 16:27:01 +0900 |
parents | cce76e5eb29b |
children | 3d71ca942a48 |
files | src/wifibroadcast/WifiBroadcastTest.java src/wifibroadcast/WifiTCP.java |
diffstat | 2 files changed, 9 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/wifibroadcast/WifiBroadcastTest.java Tue Jul 31 16:18:26 2012 +0900 +++ b/src/wifibroadcast/WifiBroadcastTest.java Tue Jul 31 16:27:01 2012 +0900 @@ -44,7 +44,7 @@ Thread.sleep(timeout/4); for(int i=0;i<wbs.length;i++) wbs[i] = new WifiMulticastChannel(i,getAddress(i),getPort(i),WifiReceiver.SocketType.Sender); } else if (tcp) { - MCASTADDR = "127.1"; + 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);
--- a/src/wifibroadcast/WifiTCP.java Tue Jul 31 16:18:26 2012 +0900 +++ b/src/wifibroadcast/WifiTCP.java Tue Jul 31 16:27:01 2012 +0900 @@ -3,12 +3,8 @@ 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.ServerSocketChannel; @@ -38,11 +34,7 @@ sAddr = new InetSocketAddress(mAddr,port); if (sender == SocketType.Receiver) { ss.bind(new InetSocketAddress(port)); - sc = ss.accept(); - if (selectMode) { - sc.configureBlocking(false); - sc.register(selector, SelectionKey.OP_READ); - } + } else { sc = SelectorProvider.provider().openSocketChannel(); sc.connect(sAddr); @@ -51,6 +43,13 @@ @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);