Mercurial > hg > Members > nobuyasu > tightVNCClient
changeset 38:0729e856169d
modify program
author | e085734 |
---|---|
date | Fri, 08 Jul 2011 21:05:03 +0900 |
parents | 73b4a33ed3db |
children | 6a81ab4df524 1b5d30103205 |
files | src/myVncClient/WaitReply.java src/myVncClient/echoClient.java |
diffstat | 2 files changed, 200 insertions(+), 215 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncClient/WaitReply.java Fri Jul 08 20:23:08 2011 +0900 +++ b/src/myVncClient/WaitReply.java Fri Jul 08 21:05:03 2011 +0900 @@ -10,7 +10,7 @@ ServerSocket echoServer=null; boolean mainFlag; - waitreply(echoClient _echo){ + WaitReply(echoClient _echo){ echo = _echo; }
--- a/src/myVncClient/echoClient.java Fri Jul 08 20:23:08 2011 +0900 +++ b/src/myVncClient/echoClient.java Fri Jul 08 21:05:03 2011 +0900 @@ -3,250 +3,235 @@ import java.io.*; import java.net.*; +public class echoClient { + public static Revalue value = new Revalue(); + WaitReply waitReply;// = new WaitReply(); + String responseLine, treenum, parent, line; + public static Socket echoSocket = null; + BufferedReader lostis = null; + public static DataOutputStream os = null; + PrintStream lostos; + public static BufferedReader is = null; + Socket clientSocket = null; + ServerSocket echoServer = null; + public static String name; -public class echoClient { - public static Revalue value = new Revalue(); - WaitReply WaitReply;// = new WaitReply(); - String responseLine,treenum,parent,line; - public static Socket echoSocket = null; - BufferedReader lostis = null; - public static DataOutputStream os = null; - PrintStream lostos; - public static BufferedReader is = null; - Socket clientSocket = null; - ServerSocket echoServer=null; - public static String name; - - //WaitReplyに自分自身を渡している - public echoClient(){ - WaitReply = new WaitReply(this); - } - - - //VncViewerから引数をもらってきてproxy役を認識する - public echoClient(String _name){ - name = _name; - } + // WaitReplyに自分自身を渡している + public echoClient() { + waitReply = new WaitReply(this); + } - // Revalue hostn(String args){ - void openport(){ - // ソケットや入出力用のストリームの宣言 - - // ポート9999番に接続 - try { - if(name != null){ - echoSocket = new Socket(name, 9999); - }else{ - echoSocket = new Socket("133.13.48.18", 9999); + // VncViewerから引数をもらってきてproxy役を認識する + public echoClient(String _name) { + name = _name; + } + + // Revalue hostn(String args){ + void openport() { + // ソケットや入出力用のストリームの宣言 + + // ポート9999番に接続 + try { + if (name != null) { + echoSocket = new Socket(name, 9999); + } else { + echoSocket = new Socket("133.13.48.18", 9999); + } + os = new DataOutputStream(echoSocket.getOutputStream()); + is = new BufferedReader(new InputStreamReader( + echoSocket.getInputStream())); + } catch (UnknownHostException e) { + System.err.println("Don't know about host: localhost"); + } catch (IOException e) { + System.err + .println("Couldn't get I/O for the connection to: localhost"); } - os = new DataOutputStream(echoSocket.getOutputStream()); - is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); - } catch (UnknownHostException e) { - System.err.println("Don't know about host: localhost"); - } catch (IOException e) { - System.err.println("Couldn't get I/O for the connection to: localhost"); - } - } - - - - /* - try { - echoServer = new ServerSocket(9998); - } - catch (IOException e) { - System.out.println(e); } - - try { - //clientSocket = echoServer.accept(); - lostis = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - lostos = new PrintStream(clientSocket.getOutputStream()); - while (true){ - line = is.readLine(); - } - } - catch (IOException e){ - System.out.println(e); - } - */ - -/* - catch(InterruptedException e){ - e.printStackTrace(); - } -*/ + + /* + * try { echoServer = new ServerSocket(9998); } catch (IOException e) { + * System.out.println(e); } + * + * try { //clientSocket = echoServer.accept(); lostis = new + * BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + * lostos = new PrintStream(clientSocket.getOutputStream()); while (true){ + * line = is.readLine(); } } catch (IOException e){ System.out.println(e); } + */ + /* + * catch(InterruptedException e){ e.printStackTrace(); } + */ + /** + * @param args + * select first connection or other + * @return + */ + Revalue hostn(String args) { + // サーバーにメッセージを送る + if (echoSocket != null && os != null && is != null) { + try { + // ip情報を取得する + InetAddress addr = InetAddress.getLocalHost(); + // System.out.println(addr.getHostAddress()); + String add = new String(addr.getHostAddress()); - /** - * @param args select first connection or other - * @return - */ - Revalue hostn(String args){ - // サーバーにメッセージを送る - if (echoSocket != null && os != null && is != null) { - try { - //ip情報を取得する - InetAddress addr = InetAddress.getLocalHost(); - //System.out.println(addr.getHostAddress()); - String add = new String(addr.getHostAddress()); - - // メッセージを送ります - os.writeBytes(add + "\n"); - os.writeBytes(args + "\n"); + // メッセージを送ります + os.writeBytes(add + "\n"); + os.writeBytes(args + "\n"); - if ((value.responseLine = is.readLine()) != null) { - System.out.println("Server: " + value.responseLine); - } - if ((value.parent = is.readLine()) != null) { - System.out.println("parent: " + value.parent); - } - if ((value.treenum = is.readLine()) != null) { - System.out.println("treenum: " + value.treenum); - } - if ((value.leaderflag = is.readLine()) != null) { - System.out.println("leaderflag: " + value.leaderflag); - } + if ((value.responseLine = is.readLine()) != null) { + System.out.println("Server: " + value.responseLine); + } + if ((value.parent = is.readLine()) != null) { + System.out.println("parent: " + value.parent); + } + if ((value.treenum = is.readLine()) != null) { + System.out.println("treenum: " + value.treenum); + } + if ((value.leaderflag = is.readLine()) != null) { + System.out.println("leaderflag: " + value.leaderflag); + } - // 開いたソケットなどをクローズ - os.close(); - is.close(); - echoSocket.close(); - } catch (UnknownHostException e) { - System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - System.err.println("IOException: " + e); + // 開いたソケットなどをクローズ + os.close(); + is.close(); + echoSocket.close(); + } catch (UnknownHostException e) { + System.err.println("Trying to connect to unknown host: " + e); + } catch (IOException e) { + System.err.println("IOException: " + e); + + } + + waitReply = new WaitReply(this); + System.out.println(waitReply); + waitReply.start(); - } - - WaitReply = new WaitReply(this); - System.out.println(WaitReply); - WaitReply.start(); - - } - return value; - } - - Revalue losthost(){ - if (echoSocket != null && os != null && is != null) { - try { - - //echoSocketの情報を呼び出す - if("1".equals(value.leaderflag)){ - //落ちた番号を報告 - os.writeBytes("1\n"); - os.writeBytes(value.parent + "\n"); - } - else{ - os.writeBytes("3\n"); - os.writeBytes(value.parent + "\n"); - } - - if ((value.responseLine = is.readLine()) != null) { - System.out.println("Server: " + value.responseLine); } - if ((value.parent = is.readLine()) != null) { - System.out.println("parent: " + value.parent); - }/* - if ((value.treenum = is.readLine()) != null) { - System.out.println("treenum: " + value.treenum); - }*/ - Thread.sleep(1000); - MyVncClient.main(value); + return value; + } + + /** + * Call at lost host + * @return + */ + Revalue losthost() { + if (echoSocket != null && os != null && is != null) { + try { + + // echoSocketの情報を呼び出す + if ("1".equals(value.leaderflag)) { + // 落ちた番号を報告 + os.writeBytes("1\n"); + os.writeBytes(value.parent + "\n"); + } else { + os.writeBytes("3\n"); + os.writeBytes(value.parent + "\n"); + } - // 開いたソケットなどをクローズ - os.close(); - is.close(); - echoSocket.close(); + if ((value.responseLine = is.readLine()) != null) { + System.out.println("Server: " + value.responseLine); + } + if ((value.parent = is.readLine()) != null) { + System.out.println("parent: " + value.parent); + }/* + * if ((value.treenum = is.readLine()) != null) { + * System.out.println("treenum: " + value.treenum); } + */ + Thread.sleep(1000); + MyVncClient.main(value); - } catch (UnknownHostException e) { - System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - System.err.println("IOException: " + e); - } catch (InterruptedException e) { - // TODO Auto-generated catch block in order to thread sleep - e.printStackTrace(); + // 開いたソケットなどをクローズ + os.close(); + is.close(); + echoSocket.close(); + + } catch (UnknownHostException e) { + System.err.println("Trying to connect to unknown host: " + e); + } catch (IOException e) { + System.err.println("IOException: " + e); + } catch (InterruptedException e) { + // TODO Auto-generated catch block in order to thread sleep + e.printStackTrace(); + } + } - + return value; } - return value; - } + + void lostchild() { - void lostchild(){ - - //ßSystem.out.println(name); - if (echoSocket != null && os != null && is != null) { - try { - - //echoSocketなどの情報を呼び出す(追加) - + // ßSystem.out.println(name); + if (echoSocket != null && os != null && is != null) { + try { - //自分の番号を報告 - os.writeBytes("2\n"); - os.writeBytes(value.treenum + "\n"); + // echoSocketなどの情報を呼び出す(追加) + + // 自分の番号を報告 + os.writeBytes("2\n"); + os.writeBytes(value.treenum + "\n"); - os.close(); - is.close(); - echoSocket.close(); + os.close(); + is.close(); + echoSocket.close(); - } catch (UnknownHostException e) { - System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - System.err.println("IOException: " + e); - } + } catch (UnknownHostException e) { + System.err.println("Trying to connect to unknown host: " + e); + } catch (IOException e) { + System.err.println("IOException: " + e); + } + } } - } - Revalue Interruption(Socket _clientSocket){ - clientSocket = _clientSocket; - + Revalue Interruption(Socket _clientSocket) { + clientSocket = _clientSocket; + try { - lostis = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + lostis = new BufferedReader(new InputStreamReader( + clientSocket.getInputStream())); lostos = new PrintStream(clientSocket.getOutputStream()); - //while (true){ - //line = lostis.readLine(); - //System.out.println(line); - - try{ - if ((value.responseLine = lostis.readLine()) != null) { + // while (true){ + // line = lostis.readLine(); + // System.out.println(line); + + try { + if ((value.responseLine = lostis.readLine()) != null) { System.out.println("newServer: " + value.responseLine); - } - if ((value.parent = lostis.readLine()) != null) { - System.out.println("newtparent: " + value.parent); - } - if ((value.treenum = lostis.readLine()) != null) { - System.out.println("newtreenum: " + value.treenum); - } - if ((value.leaderflag = lostis.readLine()) != null) { - System.out.println("newreaderflag: " + value.leaderflag); - } - - } - catch (UnknownHostException e) { - System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - System.err.println("IOException: " + e); + } + if ((value.parent = lostis.readLine()) != null) { + System.out.println("newtparent: " + value.parent); + } + if ((value.treenum = lostis.readLine()) != null) { + System.out.println("newtreenum: " + value.treenum); + } + if ((value.leaderflag = lostis.readLine()) != null) { + System.out.println("newreaderflag: " + value.leaderflag); } - - // } - }catch (IOException e){ + + } catch (UnknownHostException e) { + System.err.println("Trying to connect to unknown host: " + e); + } catch (IOException e) { + System.err.println("IOException: " + e); + } + + // } + } catch (IOException e) { System.out.println(e); } - try{ - clientSocket.close();//WaitReplyのacceptを終了させる + try { + clientSocket.close();// WaitReplyのacceptを終了させる + } catch (IOException e) { + System.out.println(e); } - catch (IOException e){ - System.out.println(e); - } return value; - } + } } -class Revalue{ - public String responseLine; - public String parent;//親の番号 - public String treenum;//自分の番号 - public String leaderflag;//リーダフラグ +class Revalue { + public String responseLine; + public String parent;// 親の番号 + public String treenum;// 自分の番号 + public String leaderflag;// リーダフラグ }