Author: jerome
Date: 2008-12-14 12:16:32 +0100 (Sun, 14 Dec 2008)
New Revision: 3105
Modified:
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/cc_main.java
Log:
* Added a check for server connection function at startup, now messages are
more clear. ( Try to get server main page, if file was retrieved, that mean
server is started, else, server isn't started).
Modified:
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/cc_main.java
===================================================================
---
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/cc_main.java
2008-12-14 10:32:39 UTC (rev 3104)
+++
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/cc_main.java
2008-12-14 11:16:32 UTC (rev 3105)
@@ -23,12 +23,19 @@
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
import java.net.UnknownHostException;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
import javax.swing.event.PopupMenuEvent;
@@ -52,6 +59,58 @@
public class cc_main{
+ public static boolean isServerStarted()
+ {
+
+ File f = null;
+
+ try
+ {
+ URL urlTest = new URL(String.format("http://%s:270/",
CcCommons.IP));
+ //Try to retreive main file of tuxdroid server.
+ URLConnection urlC = urlTest.openConnection();
+ urlC.setConnectTimeout(10);
+ InputStream inputStream = urlTest.openStream();
+ FileOutputStream fileOutputStream=null;
+
+ //Create real file.
+ f = new
File(CcCommons.TuxDroidSettingsDirectory.getAbsolutePath()
+ + File.separator + "ServerResult.htm");
+
+ f.deleteOnExit();
+
+ //Copying to file output stream
+ fileOutputStream = new FileOutputStream(f);
+ int oneChar;
+ while((oneChar=inputStream.read()) != -1)
+ {
+ fileOutputStream.write(oneChar);
+ }
+
+ inputStream.close();
+ fileOutputStream.close();
+ f.delete();
+ return true;
+ }
+
+ catch (MalformedURLException e)
+ {
+ return false;
+ }
+ catch (IOException e)
+ {
+ return false;
+ }
+
+ finally
+ {
+ if(f != null)
+ {
+ f.delete();
+ }
+ }
+ }
+
/**
* Set the fonts.
* @param f
@@ -203,6 +262,19 @@
CcCommons.IP = ip;
}
+ CcCommons.language = new
Languages(CcCommons.settings.getLocale());
+
+ //Check if server is started or not.
+ if(!cc_main.isServerStarted())
+ {
+ JOptionPane.showMessageDialog(null,
+
CcCommons.language.messages.getServerErrorMessage(),
+
CcCommons.language.getTitle(),
+
JOptionPane.ERROR_MESSAGE);
+ CcCommons.logger.append("Cannot get connected to the
Tuxdroid Server", true);
+ System.exit(0);
+ }
+
TuxAPI tux = new TuxAPI(CcCommons.IP, 270);
tux.server.connect(TuxAPIConst.CLIENT_LEVEL_ROOT,
"Control_Center", "tuxdroid");
boolean tuxb = tux.server.getConnected();
@@ -248,7 +320,7 @@
}
}
- CcCommons.language = new
Languages(CcCommons.settings.getLocale());
+
CcCommons.logger.append(CcCommons.language.getCcVersion(), true);
//Checking if new update detected.
@@ -275,7 +347,7 @@
}
}
else{
- CcCommons.logger.append("Not connected to tuxdroid
server or Control center already started.", true);
+ CcCommons.logger.append("Control center seems already
started.", true);
tux.server.disconnect();
tux.destroy();
System.gc();
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn