The Energy Detective Forums
November 24, 2014, 07:55:41 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: New TED Support forum launched!!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Getting SocketException: Connection Reset when accessing /api/LiveData.xml
ricoued
Newbie
*
Posts: 3


« on: November 15, 2011, 09:45:24 AM »

Hi All,

I'm trying to access the live data from my TED5000, but I consistently get a "connection reset".
Here is the Java code I'm using. It works fine to get other URLs but not on the TED?


         urlConnection = url.openConnection();
         is = urlConnection.getInputStream();

         BufferedReader r = new BufferedReader(new InputStreamReader(is));
         StringBuffer buf = new StringBuffer();
         String line;
         while ((line = r.readLine()) != null) {
            buf.append(line);
         }
         is.close();


Help!

Thanks,
Eric
Logged
TedDev
TED Software Developent
Administrator
Full Member
*****
Posts: 161


« Reply #1 on: November 15, 2011, 11:26:27 PM »

not sure what is going on there other than the xml file may not end with CRLF's (e.g. if it ends w/ linespace) so your r.readLine may be hanging waiting for data that is terminated before a CRLF is sent. I generally don't use readLine approach (I lean towards pulling all bytes from the stream and casting it).

However, for our current java apps, we are using Apache Commons HTTPClient to grab the data. You may want to look into that for your app as it provides many shortcuts to do exactly what you are trying to do.

String response = "";
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
try{
       int statusCode = client.executeMethod(method);
       response = method.getResponseBodyAsString();
       System.out.println(response);
        method.releaseConnection();
} catch(IOException e) {
        e.printStackTrace(System.err);
}


« Last Edit: November 15, 2011, 11:44:56 PM by TedDev » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!