Mercurial > hg > RemoteEditor > REPSessionManager
changeset 6:bdb91f4cea26
It Can connect SessionManagers each other.
author | pin |
---|---|
date | Fri, 19 Oct 2007 01:26:47 +0900 |
parents | 91a33a634fef |
children | 5067a6a93d01 |
files | rep/REP.java rep/RPanel.java rep/SessionManager.java test/TestSelsctor.java |
diffstat | 4 files changed, 45 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REP.java Thu Oct 18 13:27:06 2007 +0900 +++ b/rep/REP.java Fri Oct 19 01:26:47 2007 +0900 @@ -30,7 +30,7 @@ public static final int SMCMD_SESSION = 60; public static final int SMCMD_SESSION_ACK = 61; public static final int SMCMD_SESSION_JOIN = 62; - public static final int SMCMD_SESSION_JOIN_ACK = 62; + public static final int SMCMD_SESSION_JOIN_ACK = 63; public static final int SMCMD_UPDATE = 65; public static final int SMCMD_UPDATE_ACK = 66;
--- a/rep/RPanel.java Thu Oct 18 13:27:06 2007 +0900 +++ b/rep/RPanel.java Fri Oct 19 01:26:47 2007 +0900 @@ -31,7 +31,7 @@ public RPanel() { button = new JButton("Connect"); - textField = new JTextField("133.13.54.54"); + textField = new JTextField("firefly.cr.ie.u-ryukyu.ac.jp"); textArea = new JTextArea(); label = new JLabel("test"); scrollPane = new JScrollPane(textArea);
--- a/rep/SessionManager.java Thu Oct 18 13:27:06 2007 +0900 +++ b/rep/SessionManager.java Fri Oct 19 01:26:47 2007 +0900 @@ -32,6 +32,8 @@ //SocketChannel sessionchannel; private SessionManagerGUI sessionmanagerGUI; private Selector selector; + //private SocketChannel sessionchannel; + private boolean co; public SessionManager(int port) { sessionmanagerGUI = new SessionManagerGUI(); } @@ -54,6 +56,8 @@ ssc.configureBlocking(false); ssc.socket().bind(new InetSocketAddress(port)); ssc.register(selector, SelectionKey.OP_ACCEPT); + + // if (sessionchannel != null) { // REPPacketSend rp = new REPPacketSend(sessionchannel); // rp.send(new REPCommand(REP.SMCMD_SESSION, 0, 0, 0, 0, 0, "")); @@ -66,17 +70,16 @@ for(SelectionKey key : selector.selectedKeys()){ if(key.isAcceptable()){ SocketChannel channel = ssc.accept(); - //if(channel == null) continue; - //channel.configureBlocking(false); - //channel.register(selector, SelectionKey.OP_READ); registerChannel (selector, channel, SelectionKey.OP_READ); channel = null; - } - else if(key.isReadable()){ + }else if(key.isReadable()){ SocketChannel channel = (SocketChannel)key.channel(); REPPacketReceive repRec = new REPPacketReceive(channel); REPCommand repCom = repRec.unpack(); manager(channel, repCom); + }else if(key.isConnectable()){ + //registerChannel(selector, key.channel(), SelectionKey.OP_READ); + System.out.println("Connectable"); } } } @@ -88,6 +91,7 @@ } System.out.println("registerChannel()"); channel.configureBlocking(false); + selector.wakeup(); channel.register(selector, ops); } @@ -127,6 +131,11 @@ break; case REP.SMCMD_SESSION_JOIN: System.out.println("SMCMD_SESSION_JOIN"); + repCmd.setCMD(repCmd.cmd + 1); + REPPacketSend repSend4 = new REPPacketSend(channel); + repSend4.send(repCmd); + break; + case REP.SMCMD_SESSION_JOIN_ACK: break; case REP.REPCMD_READ: sessionlist.sendCmd(channel, repCmd); @@ -139,7 +148,7 @@ } public static void main(String[] args) throws InterruptedException, IOException { - int port = 8765; + int port = 8766; if(args.length == 1){ port = Integer.parseInt(args[1]); @@ -158,18 +167,21 @@ } private void connectSession(String host) { - int port = 8765; - SocketChannel sessionchannel; + int port = 8766; + //SocketChannel sessionchannel; //int port = Integer.parseInt(args[2]); InetSocketAddress addr = new InetSocketAddress(host, port); try { - sessionchannel = SocketChannel.open(); + SocketChannel sessionchannel = SocketChannel.open(); sessionchannel.configureBlocking(true); sessionchannel.connect(addr); - - //sessionchannel.configureBlocking(false); - + REPPacketSend send = new REPPacketSend(sessionchannel); + while(!sessionchannel.finishConnect()){ + System.out.print("."); + } + System.out.println(""); registerChannel(selector, sessionchannel, SelectionKey.OP_READ); + send.send(REPCommand.SMCMD_SESSION_JOIN); }catch (IOException e) { e.printStackTrace(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/TestSelsctor.java Fri Oct 19 01:26:47 2007 +0900 @@ -0,0 +1,19 @@ +package test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; + +public class TestSelsctor { + public static void main(String[] args) throws IOException{ + Selector selector = Selector.open(); + ServerSocketChannel ssc = ServerSocketChannel.open(); + ssc.configureBlocking(false); + ssc.socket().bind(new InetSocketAddress(8765)); + ssc.register(selector, SelectionKey.OP_ACCEPT); + + + } +}