title: Regarding HttpConnection Error
body: <p>I created a J2me program for HttpConenction to <a href="http://www.google.com" rel="nofollow">http://www.google.com</a><br>
  But when I run I get an error </p>
  
  
  
  <pre><code>error 10054 during TCP read 
  </code></pre>
  
  <p>In this I have just created a HttpConnection and reads a string from inputstream<br>
  In this an object of Httpconnection is made then the Inputstream is called which read from url ie <code>http://www.google.com</code></p>
  
  <p>Below is the code </p>
  
  <pre class="lang-java prettyprint-override"><code>import java.io.DataOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintStream;
  
  import javax.microedition.io.ConnectionNotFoundException;
  import javax.microedition.io.Connector;
  import javax.microedition.io.HttpConnection;
  import javax.microedition.io.OutputConnection;
  import javax.microedition.lcdui.Alert;
  import javax.microedition.lcdui.AlertType;
  import javax.microedition.lcdui.Command;
  import javax.microedition.lcdui.CommandListener;
  import javax.microedition.lcdui.Display;
  import javax.microedition.lcdui.Displayable;
  import javax.microedition.lcdui.Form;
  import javax.microedition.midlet.MIDlet;
  import javax.microedition.midlet.MIDletStateChangeException;
  
  
  public class NetworkFile extends MIDlet implements CommandListener {
      Form form;
      Display display;
      Command start,exit;
  
      public NetworkFile() {
          // TODO Auto-generated constructor stub
          form=new Form(null);
          exit=new Command("Exit",Command.EXIT, 0);
          start=new Command("Start",Command.OK, 1);
          form.addCommand(exit);
          form.addCommand(start);
          form.setCommandListener(this);
      }
  
      protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
          // TODO Auto-generated method stub
  
      }
  
      protected void pauseApp() {
          // TODO Auto-generated method stub
  
      }
  
      protected void startApp() throws MIDletStateChangeException {
          // TODO Auto-generated method stub
          display=Display.getDisplay(this);
          display.setCurrent(form);
      }
  
      public void commandAction(Command c, Displayable d) {
          // TODO Auto-generated method stub
  
          if (c==start) {
  
              Abc t=new Abc(this);
              t.start();
  
  
          } else if(c==exit){
              notifyDestroyed();
          }
  
  
      }
  
  }
  
  
  class Abc extends Thread
  {
      NetworkFile net1;
      HttpConnection hs=null;
      DataOutputStream requestOutputStream;
      InputStream is=null;
      StringBuffer sb=null;
      Abc(NetworkFile net1)
      {
          this.net1=net1;
      }
      public void run()
      {
          try {
              /*OutputConnection connection=(OutputConnection)Connector.open("file:///D:/lamp.txt;append=true",Connector.WRITE);
              OutputStream out=connection.openOutputStream();
              PrintStream output=new PrintStream(out);
              output.println("Hi , This is a J2ME project ");
              out.close();
              connection.close();
              Alert alert=new Alert("Alert", "Data Written", null, AlertType.INFO);
              alert.setTimeout(Alert.FOREVER);
              net1.display.setCurrent(alert);*/
  
              System.out.println("Line 1");
              hs = (HttpConnection)Connector.open("http://www.google.com",Connector.READ_WRITE, true);
              System.out.println("Line 2");
              hs.setRequestMethod(HttpConnection.POST);
              System.out.println("Line 3");
              is=hs.openInputStream();
              System.out.println("Line 4");
              int ch=0;
  
              sb = new StringBuffer();
              for (int i = 0; i &lt; 150; i++) {
                  System.out.println("Line 5");
                  ch=is.read();
                  System.out.println("Line 6");
                              if(ch==-1)
                                  {
                                      break;
                              }
                  System.out.println("ch "+ch);
                  sb.append((char)ch);
              }
  
  
  
  
          } catch (ConnectionNotFoundException e) {
              // TODO Auto-generated catch block
              System.out.println(e.toString());
              Alert alert=new Alert("Alert", " Connection ERROR !!! "+e.toString(), null, AlertType.INFO);
              alert.setTimeout(Alert.FOREVER);
              net1.display.setCurrent(alert);
          } catch (IOException e) {
              System.out.println(e.toString());
              // TODO Auto-generated catch block
              Alert alert=new Alert("Alert", " IO  ERROR !!! "+e.toString(), null, AlertType.INFO);
              alert.setTimeout(Alert.FOREVER);
              net1.display.setCurrent(alert);
          }catch (Exception e) {
              // TODO Auto-generated catch block
              System.out.println(e.toString());
              Alert alert=new Alert("Alert", " Exception  ERROR !!! "+e.toString(), null, AlertType.INFO);
              alert.setTimeout(Alert.FOREVER);
              net1.display.setCurrent(alert);
          }
          System.out.println(sb.toString());
      }
  }
  </code></pre>