Mercurial > hg > RemoteEditor > REPSessionManager
changeset 5:91a33a634fef
*** empty log message ***
author | pin |
---|---|
date | Thu, 18 Oct 2007 13:27:06 +0900 |
parents | c0db426126b6 |
children | bdb91f4cea26 |
files | rep/ConnectToSessionManager.java rep/REP.java rep/REPCommand.java rep/SessionManager.java rep/SessionManagerGUI.java rep/gui/ConnectionPanel.java rep/net/REPNet.java test/TestGUI.java |
diffstat | 8 files changed, 177 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/ConnectToSessionManager.java Thu Oct 18 13:27:06 2007 +0900 @@ -0,0 +1,28 @@ +package rep; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; + +import rep.net.REPNet; +import test.TestGUI; + +public class ConnectToSessionManager { + private SocketChannel sc; + private REPPacketReceive repreceive; + private REPPacketSend repsend; + private TestGUI gui; + private REPNet rnet; + + public static void main(String[] args){ + ConnectToSessionManager test = new ConnectToSessionManager(); + test.sm_join("localhost"); + } + + public void sm_join(String host){ + rnet = new REPNet(); + rnet.sm_connect(host, 8765); + rnet.send(REPCommand.SMCMD_SESSION_JOIN); + } + +}
--- a/rep/REP.java Tue Sep 11 18:05:29 2007 +0900 +++ b/rep/REP.java Thu Oct 18 13:27:06 2007 +0900 @@ -31,5 +31,7 @@ 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_UPDATE = 65; + public static final int SMCMD_UPDATE_ACK = 66; }
--- a/rep/REPCommand.java Tue Sep 11 18:05:29 2007 +0900 +++ b/rep/REPCommand.java Thu Oct 18 13:27:06 2007 +0900 @@ -1,6 +1,7 @@ package rep; public class REPCommand { + public static REPCommand SMCMD_SESSION_JOIN = new REPCommand(REP.SMCMD_SESSION_JOIN, 0, 0, 0, 0, 0, ""); public int cmd; public int sid; public int eid;
--- a/rep/SessionManager.java Tue Sep 11 18:05:29 2007 +0900 +++ b/rep/SessionManager.java Thu Oct 18 13:27:06 2007 +0900 @@ -29,7 +29,7 @@ private SessionList sessionlist; - SocketChannel sessionchannel; + //SocketChannel sessionchannel; private SessionManagerGUI sessionmanagerGUI; private Selector selector; public SessionManager(int port) { @@ -54,11 +54,11 @@ 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, "")); - sessionchannel.register(selector, SelectionKey.OP_READ); - } +// 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(); while(true){ @@ -126,7 +126,7 @@ sessionlist.addSessionManager(channel, repCmd); break; case REP.SMCMD_SESSION_JOIN: - + System.out.println("SMCMD_SESSION_JOIN"); break; case REP.REPCMD_READ: sessionlist.sendCmd(channel, repCmd); @@ -159,6 +159,7 @@ private void connectSession(String host) { int port = 8765; + SocketChannel sessionchannel; //int port = Integer.parseInt(args[2]); InetSocketAddress addr = new InetSocketAddress(host, port); try {
--- a/rep/SessionManagerGUI.java Tue Sep 11 18:05:29 2007 +0900 +++ b/rep/SessionManagerGUI.java Thu Oct 18 13:27:06 2007 +0900 @@ -7,6 +7,8 @@ import javax.swing.JLabel; import javax.swing.JPanel; +import rep.gui.ConnectionPanel; + public class SessionManagerGUI implements Runnable{ public static void main(String[] args) { SessionManagerGUI gui = new SessionManagerGUI(); @@ -15,12 +17,14 @@ } private RPanel rp; + //private ConnectionPanel rp; private JFrame frame; public void run() { frame = new JFrame("SessionManager"); frame.setBounds(100, 100, 400, 300); - rp = new RPanel(); + //rp = new ConnectionPanel(); + rp = new RPanel(); Container cont = frame.getContentPane(); cont.add(rp); @@ -31,14 +35,16 @@ public void addConnectionListener(ConnectionListener listener) { //System.out.println(rp.toString()); + System.out.print("waiting for launching GUI."); while(rp == null){ - System.out.println("waiting for launching GUI."); + System.out.print("."); try { - Thread.sleep(50); + Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } + System.out.println(""); rp.addConnectionListener(listener); } } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/gui/ConnectionPanel.java Thu Oct 18 13:27:06 2007 +0900 @@ -0,0 +1,57 @@ +package rep.gui; + +import java.awt.LayoutManager; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import rep.ConnectionListener; + +public class ConnectionPanel extends JPanel implements ActionListener{ + + private JButton button; + private JTextField textField; + private String host; + + public ConnectionPanel(ConnectionListener connectionlistener){ + button = new JButton("Connect"); + textField = new JTextField("localhost"); + + button.setBounds(160, 5, 100, 20); + textField.setBounds(5, 5, 150, 20); + + this.setLayout(null); + this.add(textField); + this.add( button); + + button.addActionListener(this); + } + + + public ConnectionPanel() { + button = new JButton("Connect"); + textField = new JTextField("localhost"); + + button.setBounds(160, 5, 100, 20); + textField.setBounds(5, 5, 150, 20); + + this.setLayout(null); + this.add(textField); + this.add( button); + + button.addActionListener(this); + } + + + public void actionPerformed(ActionEvent event) { + // TODO Auto-generated method stub + if (event.getSource() == button) { + host = textField.getText(); + System.out.println("pressed!"); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/net/REPNet.java Thu Oct 18 13:27:06 2007 +0900 @@ -0,0 +1,38 @@ +package rep.net; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; + +import rep.REPCommand; +import rep.REPPacketReceive; +import rep.REPPacketSend; + +public class REPNet { + private SocketChannel sc; + private REPPacketReceive repreceive; + private REPPacketSend repsend; + + public void sm_connect(String host, int port){ + //int port = 8765; + //String host = "localhost"; + InetSocketAddress addr = new InetSocketAddress(host, port); + try { + sc = SocketChannel.open(); + sc.configureBlocking(true); + sc.connect(addr); + while(!sc.finishConnect()){ + System.out.println("afro"); + } + }catch (IOException e) { + e.printStackTrace(); + } + repreceive = new REPPacketReceive(sc); + repsend = new REPPacketSend(sc); + } + + public void send(REPCommand command) { + // TODO Auto-generated method stub + repsend.send(command); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/TestGUI.java Thu Oct 18 13:27:06 2007 +0900 @@ -0,0 +1,34 @@ +package test; + +import java.awt.Container; +import java.awt.LayoutManager; + +import javax.swing.JFrame; + +import rep.ConnectToSessionManager; +import rep.ConnectionListener; +import rep.RPanel; +import rep.gui.ConnectionPanel; + +public class TestGUI { + + private static JFrame frame; + private static ConnectionPanel cp; + private static ConnectionListener listener; + + public TestGUI() { + // TODO Auto-generated constructor stub + } + + public static void main(String[] args){ + frame = new JFrame("SessionManager"); + frame.setBounds(100, 100, 400, 100); + cp = new ConnectionPanel(listener); + Container cont = frame.getContentPane(); + cont.add(cp); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + +}