Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/Editor.java @ 56:6ead43b2475e
*** empty log message ***
author | pin |
---|---|
date | Fri, 16 Nov 2007 13:58:25 +0900 |
parents | c873ee0318f8 |
children | 391d44c94799 |
line wrap: on
line diff
--- a/rep/Editor.java Tue Nov 13 20:44:21 2007 +0900 +++ b/rep/Editor.java Fri Nov 16 13:58:25 2007 +0900 @@ -1,10 +1,11 @@ package rep; import java.nio.channels.SocketChannel; +import java.util.StringTokenizer; public class Editor { private int eid; - private SocketChannel channel; + private SocketChannel myChannel; private SocketChannel nextChannel; private String host; private String port; @@ -13,11 +14,26 @@ public Editor(int editorNo, SocketChannel channel){ this.eid = editorNo; - this.channel = channel; + this.myChannel = channel; + } + + public Editor(SocketChannel channel) { + this.myChannel = channel; + setHostAndPort(myChannel); + } + + private void setHostAndPort(SocketChannel channel) { + String socketString = channel.socket().getRemoteSocketAddress().toString(); + String[] split = socketString.split("/"); + int length = split.length; + String hostAndPort = split[length-1]; + split = hostAndPort.split(":"); + host = split[0]; + port = split[1]; } public SocketChannel getChannel() { - return channel; + return myChannel; } public void setHost(String host){ @@ -42,7 +58,7 @@ this.eid = eid; } public String toString(){ - return ("eid:" + eid + ":" + channel.socket().getLocalSocketAddress().toString()); + return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString()); } public String getName() { @@ -53,4 +69,9 @@ file = string; } + public void send(REPCommand repCmd) { + REPPacketSend send = new REPPacketSend(myChannel); + send.send(repCmd); + } + }