Mercurial > hg > RemoteEditor > REPSessionManager
changeset 187:fc8ee7600cf3
*** empty log message ***
author | kent |
---|---|
date | Fri, 29 Aug 2008 17:01:25 +0900 |
parents | d22384c0026c |
children | b9855078a070 |
files | test/channeltest/StringPacker.java test/channeltest/testEditor.java test/channeltest/testNetworkSimulator.java test/channeltest/testSeMa.java test/channeltest/testSeMaSlave.java |
diffstat | 5 files changed, 48 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/test/channeltest/StringPacker.java Fri Aug 29 16:46:09 2008 +0900 +++ b/test/channeltest/StringPacker.java Fri Aug 29 17:01:25 2008 +0900 @@ -1,22 +1,26 @@ package test.channeltest; import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.CharBuffer; +import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; import rep.channel.REPPack; +import rep.channel.REPSelector; +import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; -import rep.channel.REPUnpack; -public class StringPacker implements REPPack<String>, REPUnpack<String> { +public class StringPacker implements REPPack<String> { + + public StringPacker(){ + } public ByteBuffer packUConv(String log) { int size; - ByteBuffer blog = ByteBuffer.allocate(log.length()*3); + ByteBuffer blog = ByteBuffer.allocate(log.length()*5); // TODO どれくらいにしよう? /* ヘッダ あとでもう一回書き直す */ blog.putInt(0); @@ -26,7 +30,7 @@ cb.put(log); /* ヘッダに書き込む情報 */ - size = blog.position(); + size = cb.asReadOnlyBuffer().position(); blog.rewind(); /* ヘッダ 文字列の長さ */ blog.putInt(size); @@ -42,15 +46,13 @@ */ } - public void send(String log) { - } - public String unpackUConv(SocketChannel sc) throws IOException { ByteBuffer bb = ByteBuffer.allocate(10); // ヘッダの読み込み 4Byteのハズ...? bb.limit(4); sc.read(bb); + bb.rewind(); int size = bb.getInt(); // Stringの読み込み @@ -62,21 +64,36 @@ return bb.asCharBuffer().toString(); } - /* - public String unpack(ByteBuffer data){ - data.getInt(); - //Decode UTF-8 to System Encoding(UTF-16) - Charset charset = Charset.forName("UTF-8"); - CharsetDecoder decoder = charset.newDecoder(); - CharBuffer cb = null; - try { - cb = decoder.decode(data); - } catch (CharacterCodingException e) { - } - cb.rewind(); - data.rewind(); + public static void main(String args[]){ + REPServerSocketChannel.isSimulation=false; + String str = "Hello World!"; + StringPacker sp = new StringPacker(); + SocketAddress IP = new InetSocketAddress("localhost",20000); + try { + REPSelector selector; + REPSocketChannel<String> rscS; + REPSocketChannel<String> rscC; + REPServerSocketChannel<String> rss; + + selector = REPSelector.create(); + rss = REPServerSocketChannel.<String>open(sp); + rss.socket().setReuseAddress(true); + rss.socket().bind(IP); + rss.configureBlocking(false); + rss.register(selector, SelectionKey.OP_ACCEPT, null); - return cb.toString(); - }*/ + rscC = REPSocketChannel.<String>create(sp); + rscC.connect(IP); + + rscS = rss.accept1(); + + rscC.write(str); + + System.out.println("receive `"+rscS.read()+"\'"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } }
--- a/test/channeltest/testEditor.java Fri Aug 29 16:46:09 2008 +0900 +++ b/test/channeltest/testEditor.java Fri Aug 29 17:01:25 2008 +0900 @@ -21,7 +21,7 @@ public void run(){ try { REPSocketChannel<String> channel; - channel = REPSocketChannel.<String>create(); + channel = REPSocketChannel.<String>create(new StringPacker()); ns.writeLog("try to connect to SessionManager whose ip is "+semaIP, 1); while (!channel.connect(semaIP)){
--- a/test/channeltest/testNetworkSimulator.java Fri Aug 29 16:46:09 2008 +0900 +++ b/test/channeltest/testNetworkSimulator.java Fri Aug 29 17:01:25 2008 +0900 @@ -15,8 +15,8 @@ static public REPLogger logger = REPLogger.singleton(); public static void main(String[] args){ - REPServerSocketChannel.isSimulation = true; - testNetworkSimulator testns = new testNetworkSimulator(1, 2, 5); + REPServerSocketChannel.isSimulation = false; + testNetworkSimulator testns = new testNetworkSimulator(1, 0, 2); logger.setLogLevel(5); testns.startTest();
--- a/test/channeltest/testSeMa.java Fri Aug 29 16:46:09 2008 +0900 +++ b/test/channeltest/testSeMa.java Fri Aug 29 17:01:25 2008 +0900 @@ -35,7 +35,7 @@ REPServerSocketChannel<String> scs; try { selector = REPSelector.create(); - scs = REPServerSocketChannel.<String>open(); + scs = REPServerSocketChannel.<String>open(new StringPacker()); scs.socket().setReuseAddress(true); scs.socket().bind(IP); scs.configureBlocking(false);
--- a/test/channeltest/testSeMaSlave.java Fri Aug 29 16:46:09 2008 +0900 +++ b/test/channeltest/testSeMaSlave.java Fri Aug 29 17:01:25 2008 +0900 @@ -35,7 +35,7 @@ REPSelector selector; REPSocketChannel<String> masterCH ; try { - REPServerSocketChannel<String> scs = REPServerSocketChannel.<String>open(); + REPServerSocketChannel<String> scs = REPServerSocketChannel.<String>open(new StringPacker()); selector = REPSelector.create(); masterCH = connectToMaster(selector); scs.socket().bind(ownIP); @@ -85,7 +85,7 @@ } private REPSocketChannel<String> connectToMaster(Selector _selector) throws IOException { - REPSocketChannel<String> channel = REPSocketChannel.<String>create(); + REPSocketChannel<String> channel = REPSocketChannel.<String>create(new StringPacker()); ns.writeLog("is connecting to masterSeMa whose ip is"+masterIP, 1); while(!channel.connect(masterIP)){ ns.writeLog("SeMa not listen to socket yet, wait", 1);