Mein Programm beendet sich nach unterschiedlichen Zeitabständen und wirft folgende Exeption:
Exception in thread "Timer-0" java.lang.RuntimeException: java.net.ConnectExcept
ion: Connection refused: connect
at tellonmail$1.run(tellonmail.java:139)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Und ich hab keine Ahnung woran es liegen könnte hab schon ein haufen try/catch rein gemacht um den Fehler näher zu lokalisieren aber ohne Erfolg. Vieleicht hat ja einer von euch eine Idee, danke schon mal im vorraus.
Exception in thread "Timer-0" java.lang.RuntimeException: java.net.ConnectExcept
ion: Connection refused: connect
at tellonmail$1.run(tellonmail.java:139)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Und ich hab keine Ahnung woran es liegen könnte hab schon ein haufen try/catch rein gemacht um den Fehler näher zu lokalisieren aber ohne Erfolg. Vieleicht hat ja einer von euch eine Idee, danke schon mal im vorraus.
Code:
public class tellonmail {
public static void main(String[] args) {
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run() {
String newline = System.getProperty("line.separator");
try {
int port1 = 25;
int port2 = 110;
int parity = 0;
FileWriter fon;
BufferedWriter won;
FileWriter foff;
BufferedWriter woff;
FileWriter fon2;
BufferedWriter won2;
FileWriter fail;
BufferedWriter failure;
FileReader stop = new FileReader("stop.txt");
BufferedReader Datei = new BufferedReader (stop);
String parity2 = "stop";
String Zeile = Datei.readLine();
if (Zeile.equals(parity2))
{
System.out.println("TellonMail beendet");
System.exit(1);
}
Calendar cal = new GregorianCalendar( TimeZone.getTimeZone("GMT") );
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern( "dd.MM.yyyy HH:mm:ss" );
String now = formater.format( cal.getTime() ) ;
String time = now.toString();
String fehler = "fehler.txt";
fail = new FileWriter(fehler, true);
failure = new BufferedWriter(fail);
String online1 = "online.txt";
foff = new FileWriter(online1);
woff = new BufferedWriter(foff);
String online2 = "ausfall.txt";
String online3 = "betrieb.txt";
fon = new FileWriter(online2, true);
won = new BufferedWriter(fon);
fon2 = new FileWriter(online3, true);
won2 = new BufferedWriter(fon2);
String adress = "mail.server.de";
InetAddress host = InetAddress.getByName(adress);
byte ip[] = host.getAddress();
try {
Socket sock = new Socket(host, port1);
parity = parity +1;
sock.close();
} catch (UnknownHostException e) {}
try {
Socket sock = new Socket(host, port2);
parity = parity +1;
sock.close();
} catch (UnknownHostException e) {}
if(parity == 2)
{
System.out.println(time);
try {
woff.write(time);
} catch (IOException e1) {
failure.write(time + e1 + newline);
failure.close();
}
try {
woff.close();
} catch (IOException e2) {
failure.write(time + e2 + newline);
failure.close();
}
try {
won2.write(time + newline);
} catch (IOException e3) {
failure.write(time + e3 + newline);
failure.close();
}
try {
won2.close();
} catch (IOException e4) {
failure.write(time + e4 + newline);
failure.close();
}
}
else
{
try {
won.write(time + newline);
} catch (IOException e1) {
failure.write(time + e1 + newline);
failure.close();
}
try {
won.close();
} catch (IOException e2) {
failure.write(time + e2 + newline);
failure.close();
}
}
} catch (IOException e) {
throw new RuntimeException(e );
}
}},100L,60000L);
}
}