Mercurial > hg > trac > TreeVNC > TreeVNC
annotate src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java @ 80:2951dd85e9fc
connect to real connection address instead of bad getLocalAddress().
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 30 Apr 2014 13:43:10 +0900 |
parents | fc984746f958 |
children | f93d0286c2ab |
rev | line source |
---|---|
12 | 1 package jp.ac.u_ryukyu.treevnc.client; |
1 | 2 |
3 import java.io.BufferedReader; | |
4 import java.io.IOException; | |
5 import java.io.InputStreamReader; | |
78
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
6 import java.net.InetAddress; |
1 | 7 import java.net.ServerSocket; |
8 import java.net.Socket; | |
9 | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
10 |
1 | 11 public class GetDataClient implements Runnable { |
12 private ServerSocket server = null; | |
32 | 13 private BufferedReader is; |
1 | 14 private int port = 8182; |
34 | 15 private boolean stopFlag; |
32 | 16 private TextBoxClient text = new TextBoxClient(); |
45 | 17 private String proxyAddr; |
77 | 18 |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
19 public String textAddress() { |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
20 return text.getAddress(); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
21 } |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
22 |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
23 public String textPort() { |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
24 return text.getPort(); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
25 } |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
26 |
1 | 27 void socketClose() { |
28 try { | |
29 text.unVisible(); | |
30 is.close(); | |
31 } catch (IOException e) { | |
32 e.printStackTrace(); | |
33 } | |
34 } | |
35 | |
32 | 36 @Override |
1 | 37 public void run() { |
32 | 38 try { |
39 server = new ServerSocket(port); | |
34 | 40 while(!stopFlag) { |
32 | 41 Socket socket = server.accept(); |
42 is = new BufferedReader(new InputStreamReader( | |
43 socket.getInputStream())); | |
45 | 44 proxyAddr = is.readLine(); |
78
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
45 // proxyAddr format |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
46 // 5999:localhost:localhost:133.13.59.210: |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
47 // port:hostnae:hostname:ip address: |
80
2951dd85e9fc
connect to real connection address instead of bad getLocalAddress().
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
78
diff
changeset
|
48 // GetBroadCastProxy create this string on VNC root |
78
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
49 InetAddress adr = socket.getInetAddress(); |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
50 String proxyAddr1 = adr.getHostName(); |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
51 if (proxyAddr1 != null) { |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
52 int portIndex = proxyAddr.indexOf(":"); |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
53 int restIndex = proxyAddr.indexOf(":", portIndex+1); |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
54 if (portIndex>0) { |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
55 proxyAddr = proxyAddr.substring(0, portIndex)+":"+proxyAddr1 + ":" + proxyAddr.substring(restIndex+1); |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
56 } |
fc984746f958
use real ip address for TreeVNC root selection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
57 } |
45 | 58 if(proxyAddr!=null) |
59 text.checkBox(proxyAddr); | |
32 | 60 text.setButton(); |
61 text.visible(); | |
62 } | |
34 | 63 System.out.println("stop"); |
32 | 64 } catch (IOException e) { |
65 e.printStackTrace(); | |
66 } | |
1 | 67 } |
68 | |
69 public void setStopFlag(boolean stopFlag) { | |
70 this.stopFlag = stopFlag; | |
34 | 71 |
72 } | |
73 | |
74 public void interrupt() { | |
75 Thread.currentThread().interrupt(); | |
1 | 76 } |
77 | |
78 public boolean isStopFlag() { | |
79 return stopFlag; | |
80 } | |
32 | 81 |
82 public void ipRegister() { | |
83 text.ipRegister(); | |
84 } | |
1 | 85 |
45 | 86 public String getProxyAddr() { |
87 return proxyAddr; | |
88 } | |
1 | 89 } |