diff options
Diffstat (limited to 'NET/worlds/network/WSConnecting.java')
| -rw-r--r-- | NET/worlds/network/WSConnecting.java | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/NET/worlds/network/WSConnecting.java b/NET/worlds/network/WSConnecting.java new file mode 100644 index 0000000..c1af509 --- /dev/null +++ b/NET/worlds/network/WSConnecting.java @@ -0,0 +1,217 @@ +/* */ package NET.worlds.network; +/* */ +/* */ import java.io.IOException; +/* */ import java.io.PrintStream; +/* */ import java.net.NoRouteToHostException; +/* */ import java.net.Socket; +/* */ import java.net.UnknownHostException; +/* */ import java.util.StringTokenizer; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ class WSConnecting +/* */ implements Runnable +/* */ { +/* */ private WorldServer _serv; +/* */ private String _host; +/* */ private Vector<String> _hosts; +/* */ private int _unresolvedHosts; +/* */ private int _port; +/* */ private int _timeout; +/* */ private int _error; +/* */ private boolean _calledBack; +/* */ private Vector<String> _resolvedHosts; +/* */ +/* */ public WSConnecting(WorldServer serv, String host, int port, int timeout) +/* */ { +/* 40 */ this._serv = serv; +/* 41 */ this._host = host; +/* 42 */ this._hosts = new Vector(); +/* 43 */ this._port = port; +/* 44 */ this._timeout = timeout; +/* 45 */ this._error = 0; +/* */ +/* */ +/* 48 */ makeThread(-1); +/* */ +/* */ +/* */ +/* 52 */ StringTokenizer tok = new StringTokenizer(host, ";"); +/* 53 */ while (tok.hasMoreTokens()) +/* 54 */ this._hosts.addElement(tok.nextToken()); +/* 55 */ this._unresolvedHosts = this._hosts.size(); +/* */ +/* */ +/* 58 */ for (int i = 0; i < this._unresolvedHosts; i++) +/* */ { +/* */ +/* 61 */ makeThread(i); +/* */ } +/* */ } +/* */ +/* */ private void makeThread(int index) { +/* 66 */ Thread t = new Thread(this, Integer.toString(index)); +/* 67 */ t.setDaemon(true); +/* 68 */ t.start(); +/* */ } +/* */ +/* */ public void run() +/* */ { +/* 73 */ int index = Integer.parseInt(Thread.currentThread().getName()); +/* */ +/* */ +/* 76 */ if (index == -1) { +/* */ try { +/* 78 */ Thread.sleep(this._timeout * 1000); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* 81 */ synchronized (this) { +/* 82 */ if (!this._calledBack) { +/* 83 */ this._calledBack = true; +/* 84 */ if (this._error == 0) +/* 85 */ this._error = 106; +/* 86 */ this._serv.setSocket(null, new VarErrorException(this._error), null); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* 93 */ if (index < this._unresolvedHosts) { +/* */ try { +/* 95 */ String host = (String)this._hosts.elementAt(index); +/* 96 */ String[] addresses = DNSLookup.lookupAll(host); +/* 97 */ if (addresses.length > 1) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 116 */ for (int i = 0; i < addresses.length; i++) +/* */ { +/* 118 */ synchronized (this._hosts) { +/* 119 */ int newIndex = this._hosts.size(); +/* */ +/* */ +/* */ +/* */ +/* */ +/* 125 */ this._hosts.addElement(addresses[i]); +/* */ } +/* */ +/* */ int newIndex; +/* */ +/* 130 */ makeThread(newIndex); +/* */ } +/* */ +/* */ } else +/* 134 */ connectTo(addresses[0], false); +/* */ } catch (UnknownHostException uhe) { +/* 136 */ synchronized (this) { +/* 137 */ if (this._error == 0) { +/* 138 */ this._error = 107; +/* */ +/* */ } +/* */ +/* */ +/* */ } +/* */ +/* */ +/* */ } +/* */ +/* */ +/* */ } +/* */ else +/* */ { +/* */ +/* 153 */ connectTo((String)this._hosts.elementAt(index), false); +/* */ } +/* */ } +/* */ +/* */ public Vector<String> getBackupHosts() +/* */ { +/* 159 */ this._resolvedHosts = new Vector(); +/* 160 */ for (int i = this._unresolvedHosts; i < this._hosts.size(); i++) { +/* 161 */ this._resolvedHosts.addElement((String)this._hosts.elementAt(i)); +/* */ } +/* 163 */ return this._resolvedHosts; +/* */ } +/* */ +/* */ private void connectTo(String host, boolean delay) { +/* 167 */ Socket sock = null; +/* */ +/* */ try +/* */ { +/* 171 */ sock = new Socket(host, this._port); +/* */ +/* 173 */ synchronized (this) +/* */ { +/* */ +/* */ +/* 177 */ if (delay) { +/* */ try { +/* 179 */ wait(this._timeout * 1000 * 2 / 3); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* */ } +/* */ +/* 184 */ System.out.println("Connected to " + host); +/* */ +/* 186 */ if (!this._calledBack) { +/* 187 */ this._calledBack = true; +/* 188 */ this._serv.setSocket(sock, null, host); +/* */ } else { +/* */ try { +/* 191 */ sock.close(); +/* */ } +/* */ catch (IOException localIOException1) {} +/* */ } +/* 195 */ notifyAll(); +/* */ } +/* */ } +/* */ catch (IOException e) { +/* 199 */ synchronized (this) { +/* 200 */ if (this._error == 0) { +/* 201 */ if (((e instanceof NoRouteToHostException)) || +/* 202 */ ((e instanceof UnknownHostException))) { +/* 203 */ this._error = 107; +/* */ } else +/* 205 */ this._error = 104; +/* */ } +/* 207 */ notifyAll(); +/* */ } +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\WSConnecting.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |