Mercurial > hg > Applications > TreeVNC
changeset 92:ca39d762805e
NoConnection implies no needReconnection Viewer,
reconnectionWaiter clean up(waitReply),
sendReconnection clean up(createSocketAndSend).
author | oc |
---|---|
date | Mon, 19 May 2014 18:48:35 +0900 |
parents | cec9f6aa9398 |
children | 7b8d3411270a |
files | src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/ReconnectionWaiter.java src/main/java/jp/ac/u_ryukyu/treevnc/client/WaitReply.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java |
diffstat | 5 files changed, 57 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java Mon May 19 10:52:07 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java Mon May 19 18:48:35 2014 +0900 @@ -11,7 +11,7 @@ private DataOutputStream os = null; private Socket echoSocket = null; private boolean runflag = false; - private WaitReply waitReply; + private ReconnectionWaiter waitReply; private Socket clientSocket = null; private int echoPort = 9999; public ViewerImpl client; @@ -62,7 +62,7 @@ } catch (IOException e) { System.err.println("IOException: " + e); } - waitReply = new WaitReply(treeNum, this); + waitReply = new ReconnectionWaiter(treeNum, this); waitReply.start(); } return this; @@ -257,9 +257,4 @@ return parentAddress; } - public void reportConnectionFinished(Socket soc) throws IOException { - DataOutputStream os = new DataOutputStream(soc.getOutputStream()); - os.writeBytes("finished"); - } - } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/ReconnectionWaiter.java Mon May 19 18:48:35 2014 +0900 @@ -0,0 +1,47 @@ +package jp.ac.u_ryukyu.treevnc.client; + +import java.io.IOException; +import java.net.BindException; +import java.net.ServerSocket; +import java.net.Socket; + + +/** + * Wait for reconnection message. + * Close current application and reopen it. + */ +public class ReconnectionWaiter extends Thread { + private EchoClient echo; + + public ReconnectionWaiter(String treenum, EchoClient echo) { + this.echo = echo; + } + + + public void run() { + ServerSocket echoServer = null; + try { + echoServer = new ServerSocket(10001); + while (true) { + Socket clientSocket = echoServer.accept(); + if (clientSocket != null) { + echo.client.setTeminationType(true); + echo.client.closeApp(); + echo.client.setSocket(echo.createSocketForClient(clientSocket,true)); + echo.client.run(); + clientSocket.close(); + } + } + } catch (BindException e) { + return; + } catch (IOException e) { + System.out.println(e); + } finally { + try { + echoServer.close(); + } catch (IOException e) { + return; + } + } + } +}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/WaitReply.java Mon May 19 10:52:07 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -package jp.ac.u_ryukyu.treevnc.client; - -import java.io.IOException; -import java.net.BindException; -import java.net.ServerSocket; -import java.net.Socket; - - -/** - * this Class get top(Proxy) Instruction. - * Type of Instruction is ReConnection and SocketClose. - */ -public class WaitReply extends Thread { - private boolean passflag; - private EchoClient echo; - - public WaitReply(String treenum, EchoClient echo) { - this.echo = echo; - } - - public boolean checkPath() { - return passflag; - } - - public void run() { - Socket clientSocket = null; - ServerSocket echoServer = null; - while (true) { - try { - echoServer = new ServerSocket(10001); - clientSocket = echoServer.accept(); - if (clientSocket != null) { - echo.client.setTeminationType(true); - //echo.client.closeApp(); - passflag = true; - echo.client.closeApp(); - echo.client.setSocket(echo.createSocketForClient(clientSocket,true)); - echo.client.run(); - echoServer.close(); - //report finished connection to server. - echo.reportConnectionFinished(clientSocket); - //echo.client.stop(); - - clientSocket.close(); - - } - } catch (BindException e) { - break; - } catch (IOException e) { - System.out.println("Error in WaitReply L47"); - System.out.println(e); - } - } - } - - /* - private void hult() throws IOException { - Socket socket = new Socket("localhsot", echo.client.getPort()); - OutputStream stream = socket.getOutputStream(); - stream.write("halt".getBytes()); - stream.flush(); - } - */ -}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Mon May 19 10:52:07 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Mon May 19 18:48:35 2014 +0900 @@ -33,7 +33,7 @@ private String reconnectionReason; private AcceptThread acceptThread; private GetBroadCastProxy getCast; - public AcceptClient aClient; + private AcceptClient clients; public int opendPort; static VncProxyService currentVps; private int fbWidth = 0; @@ -55,7 +55,7 @@ reconnectionReason = vps.reconnectionReason; acceptThread = vps.acceptThread; getCast = vps.getCast; - aClient = vps.aClient; + clients = vps.clients; opendPort = vps.opendPort; } @@ -78,7 +78,7 @@ private void initProxy1(String hostName) { myRfb = new MyRfbProtoProxy(); - aClient = new AcceptClient(); + clients = new AcceptClient(); isApplet = false; setIsTreeVNC(true); setConnectionParam(hostName,vncport); @@ -142,7 +142,7 @@ } private void threadSetAndStart() throws UnknownHostException, IOException { - CreateThread createThread = new CreateThread(aClient); + CreateThread createThread = new CreateThread(clients); Thread thread = new Thread(createThread); thread.start(); Thread thread2 = new Thread(new ChangeHost(this, forceReconnection)); @@ -201,7 +201,7 @@ } - private void createSocketAndSend(LinkedList<String> clientList, + private void sendReconnection(LinkedList<String> clientList, String host, String port) throws UnknownHostException, IOException { boolean passFlag = false; int counter = 0; @@ -211,7 +211,7 @@ DataOutputStream os = new DataOutputStream( echoSocket.getOutputStream()); os.writeBytes("reconnection\n"); - if(counter++ < aClient.getTreeBranch()) + if(counter++ < clients.getTreeBranch()) os.writeBytes(port + "\n"); else os.writeBytes(5999 + "\n"); @@ -259,7 +259,7 @@ int count = 0; while(true) { if(vps.myRfb.getReadyReconnect()) { - vps.createSocketAndSend(aClient.getList(), hostName, String.valueOf(vps.opendPort)); + vps.sendReconnection(clients.getList(), hostName, String.valueOf(vps.opendPort)); break; } else { try {
--- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Mon May 19 10:52:07 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Mon May 19 18:48:35 2014 +0900 @@ -96,6 +96,7 @@ public void setNoConnection(boolean c){ noConnection = c; + needReconnection = false; } public void setUseSsh(boolean useSsh) {