Mercurial > hg > RemoteEditor > REPSessionManager
changeset 14:47633cfb92d3
*** empty log message ***
author | pin |
---|---|
date | Fri, 02 Nov 2007 14:15:26 +0900 |
parents | 00714676d05b |
children | 78c211017d3d |
files | rep/REPPacketReceive.java rep/SessionManager.java |
diffstat | 2 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPPacketReceive.java Fri Nov 02 13:59:29 2007 +0900 +++ b/rep/REPPacketReceive.java Fri Nov 02 14:15:26 2007 +0900 @@ -10,6 +10,8 @@ SocketChannel socketchannel; private int HEADER_SIZE = 24; + private String host; + private int port; public REPPacketReceive(SocketChannel sc){ socketchannel = sc; @@ -63,7 +65,7 @@ } String string = text; //System.out.println(string); - getSocket(string); + //getSocket(string); REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); System.out.println("received command: " + repcommand.toString()); return repcommand; @@ -71,15 +73,13 @@ private void getSocket(String string) { - StringTokenizer token = new StringTokenizer(string, "/:"); - LinkedList<String> tokenlist = new LinkedList<String>(); - while(token.hasMoreTokens()){ - tokenlist.add(token.nextToken()); + StringTokenizer st = new StringTokenizer(string, "/"); + String hostport = null; + while(st.hasMoreTokens()){ + hostport = st.nextToken(); } - int port = Integer.parseInt(tokenlist.getLast()); - tokenlist.removeLast(); - String host = tokenlist.getLast(); - tokenlist.removeLast(); - System.out.println(host + ":" + port); + StringTokenizer st2 = new StringTokenizer(hostport, ":"); + host = st2.nextToken(); + port = Integer.parseInt(st2.nextToken()); } }
--- a/rep/SessionManager.java Fri Nov 02 13:59:29 2007 +0900 +++ b/rep/SessionManager.java Fri Nov 02 14:15:26 2007 +0900 @@ -232,6 +232,8 @@ } System.out.println(""); registerChannel(selector, sessionchannel, SelectionKey.OP_READ); + REPCommand sm_join_com = REPCommand.SMCMD_SESSION_JOIN; + sm_join_com.setString(sm_join_com.string + getSocket(sessionchannel)); send.send(REPCommand.SMCMD_SESSION_JOIN); smList.add(sessionchannel); }catch (IOException e) { @@ -239,6 +241,11 @@ } } + private String getSocket(SocketChannel sessionchannel) { + SocketAddress socket = sessionchannel.socket().getRemoteSocketAddress(); + return socket.toString(); + } + public void connectionOccured(ConnectionEvent event) { connectSession(event.getHost()); }