Mercurial > hg > Applications > TightVNC_orginal
annotate src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java @ 41:0f260079879f
add setReuseAddress
author | one |
---|---|
date | Mon, 22 Oct 2012 17:51:02 +0900 |
parents | 1b81deb0abb3 |
children | 20326a4b9d88 |
rev | line source |
---|---|
11 | 1 package com.glavsoft.viewer; |
2 | |
3 import java.awt.event.WindowListener; | |
4 import java.io.IOException; | |
5 import java.net.Socket; | |
6 import java.net.UnknownHostException; | |
7 | |
35 | 8 import jp.ac.u_ryukyu.treevnc.MyRfbProto; |
12 | 9 import jp.ac.u_ryukyu.treevnc.client.GetDataClient; |
10 import jp.ac.u_ryukyu.treevnc.client.GetHostClient; | |
32 | 11 import jp.ac.u_ryukyu.treevnc.client.EchoClient; |
11 | 12 |
13 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
14 import com.glavsoft.viewer.swing.ParametersHandler; | |
15 | |
16 public class TreeConnectionManager extends ConnectionManager { | |
17 | |
18 /** | |
19 * | |
20 */ | |
21 private static final long serialVersionUID = 1L; | |
32 | 22 |
11 | 23 public TreeConnectionManager(WindowListener appWindowListener, |
24 boolean isApplet) { | |
25 super(appWindowListener, isApplet); | |
26 } | |
27 | |
28 @Override | |
35 | 29 public Socket connectToHost(final ParametersHandler.ConnectionParams connectionParams, |
30 ProtocolSettings settings, MyRfbProto rfb) { | |
11 | 31 Socket socket = null; |
32 GetHostClient bCast = new GetHostClient("who"); | |
34 | 33 bCast.getHost(); |
32 | 34 GetDataClient getBcast = new GetDataClient(); |
35 Thread runBcast = new Thread(getBcast); | |
36 runBcast.start(); | |
37 connectionParams.hostName = getBcast.textAddress(); | |
34 | 38 getBcast.interrupt(); |
11 | 39 if("notFound".equals(connectionParams.hostName)) { |
32 | 40 // connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); |
41 connectionParams.portNumber = 5900; | |
42 } else { | |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
43 // getBcast.ipRegister(); |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
44 EchoClient echo = new EchoClient(getBcast.textAddress(),9999); |
35 | 45 rfb.setEcho(echo); |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
46 echo.getParentName(); |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
47 connectionParams.hostName = echo.parentAddress; |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
48 connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); // I should get port number |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
49 // connectionParams.hostName = getBcast.textAddress(); |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
50 // connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
51 // connectionParams.portNumber = 5900; |
11 | 52 } |
53 Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber); | |
54 try { | |
55 socket = new Socket(connectionParams.hostName, connectionParams.portNumber); | |
41 | 56 socket.setReuseAddress(true); |
11 | 57 } catch (UnknownHostException e) { |
58 Viewer.logger.severe("Unknown host: " + connectionParams.hostName); | |
59 showConnectionErrorDialog("Unknown host: '" + connectionParams.hostName + "'"); | |
60 } catch (IOException e) { | |
61 Viewer.logger.severe("Couldn't connect to: " + | |
62 connectionParams.hostName + ":" + connectionParams.portNumber + | |
63 ": " + e.getMessage()); | |
64 showConnectionErrorDialog("Couldn't connect to: '" + connectionParams.hostName + | |
65 "'\n" + e.getMessage()); | |
66 } | |
67 return socket; | |
68 } | |
69 | |
70 } |