This discussion is archived
3 Replies Latest reply: Apr 21, 2009 1:10 AM by 843851 RSS

Connection Refused Exception getting a file from Internet

843851 Newbie
Currently Being Moderated
I don't manage to get a file (a RSS type XML) from Internet , I get a connection refused exception, but I don't know why?. The STB has ethernet conection an asigned IP.
This is my code:
public int load()
{
               BufferedReader bufferReader=null;
               ConnectionRCInterface myInterface=null;
               FileWriter fileWriter=null;
               String inputLine;
               InputStream inpStrm=null;
               InputStreamReader inpStrmReader=null;
               RCInterfaceManager rcm=null;
               try {
                    rcm =RCInterfaceManager.getInstance();
                    RCInterface[] interfaces = rcm.getInterfaces();
                    if (interfaces[0] instanceof ConnectionRCInterface) {
                      myInterface = (ConnectionRCInterface)interfaces[0];
                      try {
                        myInterface.reserve(this,null);
                        ConnectionParameters myConnectionParameters;
                        myConnectionParameters = new ConnectionParameters
                          (ConfigParser.getModemNumber(), ConfigParser.getModemUser(), ConfigParser.getModemPassword());
                        myInterface.setTarget(myConnectionParameters);
                        myInterface.addConnectionListener(this);
                        myInterface.connect();
                      } catch (PermissionDeniedException pde) {
                              Logger.error(this,"load():  PermissionDeniedException= "+pde.getMessage());
                           return Constants.ERROR;
                      } catch (IncompleteTargetException ite) {
                              Logger.error(this,"load():  IncompleteTargetException= "+ite.getMessage());
                           return Constants.ERROR;
                      }
                    }
                  SocketFactory sFact = (SocketFactory) SocketFactory.getDefault();
                    Socket readerSock = (Socket) sFact.createSocket(BASE_URL+url, 80);
                    Logger.debug(this,"load(): Connected to http://gipuzkoa.net/ in port 80");
                    inpStrm=readerSock.getInputStream();
                    inpStrmReader=new InputStreamReader(inpStrm,"UTF-8");
                    bufferReader=new BufferedReader(inpStrmReader);
                    fileWriter=new FileWriter(file);
                    BufferedWriter buffWriter=new BufferedWriter(fileWriter);
                             inputLine=bufferReader.readLine();
                             do{
                      buffWriter.write(inputLine);
                      inputLine=bufferReader.readLine();
                 }
                 while((inputLine!=null) && (inputLine.length()!=0));
            
                    } catch (UnknownHostException uhe) {
                         Logger.error(this," loadFile():  UnknownHostException= "+uhe.getMessage());
                      return Constants.ERROR;
                    } catch (IOException ioe) {
                         Logger.error(this,"loadFile():  IOException= "+ioe.getMessage());
                      return Constants.ERROR;
                    }
                    finally{
                         if(myInterface!=null){
                             try {
                                   myInterface.disconnect();
                                   myInterface.removeConnectionListener(this);
                                   myInterface.release();
                              } catch (PermissionDeniedException pde) {
                                   Logger.debug(this, "load():PermissionDeniedException= "+pde.getMessage());
                                   return Constants.ERROR;
                              }
                         }
                         try {
                              if(inpStrm!=null){
                                   inpStrm.close();
                              }
                              if(inpStrmReader!=null){
                                   inpStrmReader.close();
                              }
                              if(fileWriter!=null){
                                   fileWriter.close();
                              }
                         } catch (IOException ioe) {
                              Logger.debug(this, "load():PermissionDeniedException= "+ioe.getMessage());
                         }
                    }
}
          
Any idea?
thank in advance

Edited by: apenz on Mar 17, 2009 4:12 PM
  • 1. Re: Connection Refused Exception getting a file from Internet
    843851 Newbie
    Currently Being Moderated
    If your STB has an ethernet connection and you configured it correctly from the STB menu (sometimes here is the error) there's no need for all that configuration. You can create a socket without the socket factory and work with it as you would in J2SE to retrieve the file.
  • 2. Re: Connection Refused Exception getting a file from Internet
    843851 Newbie
    Currently Being Moderated
    Hi!
    i am wroking on the Return Channel to get some data from the internet or local web server. can any body tell me that what exactly the return channel interface doing. because we can also get the content by using the url class and opening by their stream.
    it may be very basic question but i have not got the proper documentation so i am asking to you people.
    thank in advance.
  • 3. Re: Connection Refused Exception getting a file from Internet
    843851 Newbie
    Currently Being Moderated
    The RC is a conection through internet that usually is used for sending user data and personalize the response for each user. Your STB has to have an ethernet input or otherwise a modem inside it. You have to configure your STB's IP configuration. And of course you can use it to connect to a URL and get information from a URL opening the connection in the usual way.

    And Thanks I've solved my problem and I can connect to the URL correctly simply using URL class.
    Greetings

    Edited by: apenz on Apr 21, 2009 8:07 AM