Mercurial > hg > RemoteEditor > REPSessionManager
changeset 7:5067a6a93d01
*** empty log message ***
author | pin |
---|---|
date | Fri, 19 Oct 2007 05:16:38 +0900 |
parents | bdb91f4cea26 |
children | b774b87cc2c1 |
files | rep/SessionManager.java rep/SessionManagerList.java test/TestSelector.java test/TestSelsctor.java |
diffstat | 4 files changed, 50 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/SessionManager.java Fri Oct 19 01:26:47 2007 +0900 +++ b/rep/SessionManager.java Fri Oct 19 05:16:38 2007 +0900 @@ -32,8 +32,9 @@ //SocketChannel sessionchannel; private SessionManagerGUI sessionmanagerGUI; private Selector selector; + private SessionManagerList smList; //private SocketChannel sessionchannel; - private boolean co; + //private boolean co; public SessionManager(int port) { sessionmanagerGUI = new SessionManagerGUI(); } @@ -58,12 +59,8 @@ 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, "")); -// sessionchannel.register(selector, SelectionKey.OP_READ); -// } sessionlist = new SessionList(); + smList = new SessionManagerList(); while(true){ selector.select(); @@ -78,7 +75,6 @@ REPCommand repCom = repRec.unpack(); manager(channel, repCom); }else if(key.isConnectable()){ - //registerChannel(selector, key.channel(), SelectionKey.OP_READ); System.out.println("Connectable"); } } @@ -103,7 +99,6 @@ repCmd.setEID(eid); repCmd.setCMD(repCmd.cmd + 1); repCmd.string = sessionlist.getSessionList(); - //sessionlist.getSessionList(); REPPacketSend repSend = new REPPacketSend(channel); repSend.send(repCmd); break; @@ -112,6 +107,7 @@ break; case REP.SMCMD_PUT: int sessionID = sessionlist.addSession(channel, repCmd.string); + smList.update(sessionID, repCmd.string); repCmd.setSID(sessionID); repCmd.setCMD(repCmd.cmd + 1); REPPacketSend repSend2 = new REPPacketSend(channel); @@ -130,7 +126,7 @@ sessionlist.addSessionManager(channel, repCmd); break; case REP.SMCMD_SESSION_JOIN: - System.out.println("SMCMD_SESSION_JOIN"); + smList.add(channel); repCmd.setCMD(repCmd.cmd + 1); REPPacketSend repSend4 = new REPPacketSend(channel); repSend4.send(repCmd); @@ -182,6 +178,7 @@ System.out.println(""); registerChannel(selector, sessionchannel, SelectionKey.OP_READ); send.send(REPCommand.SMCMD_SESSION_JOIN); + smList.add(sessionchannel); }catch (IOException e) { e.printStackTrace(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/SessionManagerList.java Fri Oct 19 05:16:38 2007 +0900 @@ -0,0 +1,25 @@ +package rep; + +import java.nio.channels.SocketChannel; +import java.util.LinkedList; +import java.util.List; + +public class SessionManagerList { + + private List<SocketChannel> list = new LinkedList<SocketChannel>(); + private int mySMID; + + public void add(SocketChannel channel) { + // TODO Auto-generated method stub + list.add(channel); + } + + public void update(int sessionID, String string) { + // TODO Auto-generated method stub + for(SocketChannel channel : list){ + REPPacketSend send = new REPPacketSend(channel); + send.send(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string.length(), string)); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/TestSelector.java Fri Oct 19 05:16:38 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 TestSelector { + 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); + + + } +}
--- a/test/TestSelsctor.java Fri Oct 19 01:26:47 2007 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -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); - - - } -}