1
JavaOp Support Archive / Re: JavaOp 2.1.2 To-Do List:
« on: September 15, 2009, 06:15:15 pm »
changelog goes in SVN commit! Generalizations = bad!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Originally posted by "Dirk"...
A friend of mine recently bought a product called PrintMaster. He had some trouble installing the software and called me up for some tech support. He was receiving an Error 1305, for which a quick Google search lead me towards the following:
... Completing a clean installation of the program will help to prevent conflicts that can occur. The remainder of this note describes the procedure...
All right, I thought a clean install, let's read on and see how to do a clean install:
1. Place a small amount of nonabrasive, liquid soap on the shiny side of the CD or DVD.
2. Using your fingertips and warm water, gently rub the soap on the disc in a circular motion.
3. Rinse the disc thoroughly and dry it using a clean, soft T-shirt or lint-free towel. Do not use paper towels or tissue paper.
4. Install the program.
Doing a "clean install" has now taken on a new meaning for me.
/*
* Find the fastest mirror! :)
*/
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
public class MirrorSelector {
private static boolean DEBUG = false;
private static int MAX_TIME = 1000; // timeout time in ms and default length if an error occurs
public static InetSocketAddress selectMirror(InetSocketAddress[] mirrors)
{
Socket s = new Socket();
long[] times = new long[mirrors.length];
long start;
for(int i=0;i<mirrors.length;i++)
{
try{
s = new Socket();
start = System.currentTimeMillis();
s.connect(mirrors[i], MAX_TIME);
times[i] = System.currentTimeMillis() - start;
s.close();
if(DEBUG)
System.out.println("Connecting to " + mirrors[i] + " took " + times[i] + "ms");
}
/* I considered condensing all the specific exceptions into a generic handler
* since they all respond basically the same way
*/
catch(SocketTimeoutException ste)
{
System.out.println("Address " + mirrors[i] + " timed out");
times[i] = MAX_TIME;
}
catch(ConnectException ce)
{
System.out.println("Connect Exception: " + ce.getMessage() + " for " + mirrors[i]);
if(DEBUG)
ce.printStackTrace();
times[i] = MAX_TIME;
}
catch(SocketException se)
{
System.out.println("Unable to connect to " + mirrors[i]
+", there may be a problem with your network connection.");
if(DEBUG)
se.printStackTrace();
times[i] = MAX_TIME;
}
catch(IOException ioe)
{
System.out.println("Error connecting to " + mirrors[i]);
if(DEBUG)
ioe.printStackTrace();
times[i] = MAX_TIME;
}
}
int fast_id = 0;
long fast_time = MAX_TIME;
for(int i=0;i<times.length;i++)
{
if(times[i] < fast_time)
{
fast_id = i;
fast_time = times[i];
}
}
return mirrors[fast_id];
}
public static InetSocketAddress getClosestMirror(String hostname, int port)
{
InetAddress[] ips;
try{
ips = InetAddress.getAllByName(hostname);
}
catch(UnknownHostException uhe)
{
System.out.println("Unable to resolve host: " + port);
return null;
}
InetSocketAddress[] mirrors = new InetSocketAddress[ips.length];
for(int i=0;i<ips.length;i++)
{
mirrors[i] = new InetSocketAddress(ips[i], port);
}
return selectMirror(mirrors);
}
public static void main(String[] args)
{
System.out.println("Fastest: " + getClosestMirror("google.com", 80));
}
}
:loop
;// execute a shell command
IF ERRORLEVEL == 1 GOTO loop
pause > nul