Results 1 to 3 of 3
  1. #1
    girija is offline Member
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Default HttpConnection problem

    In my code I am sending the request to server and response also i am receiving
    after this one outputstream is not working one exception is came that is


    java.lang.IllegalStateException: Write attempted after request finished
    at com.sun.midp.io.j2me.http.Protocol.writeBytes(Prot ocol.java:997)
    at com.sun.midp.io.BaseOutputStream.write(ConnectionB aseAdapter.java:696)
    at java.io.OutputStream.write(OutputStream.java:58)
    at MobileMail.SendAndreceiveData(MobileMail.java:1211 )
    at MobileMail.Connection(MobileMail.java:481)
    at MobileMail.startdata(MobileMail.java:368)
    at MobileMail.startApp(MobileMail.java:170)
    at javax.microedition.midlet.MIDletProxy.startApp(MID letProxy.java:44)
    at com.sun.midp.midlet.Scheduler.schedule(Scheduler.j ava:372)
    at com.sun.midp.main.Main.runLocalClass(Main.java:461 )
    at com.sun.midp.main.Main.main(Main.java:126)


    I amrequrired to send ofter that one so plz help me


    My code is

    public void Connection() {

    {

    try {

    socket = (HttpConnection) Connector.open("http://" +
    ipAddress.getString() + ":80");

    //HTTP Request
    socket.setRequestMethod(HttpConnection.GET);
    socket.setRequestProperty("Content-Type", "//text plain");
    socket.setRequestProperty("Connection", "Keep-Alive");
    out = socket.openOutputStream();
    //socket.setRequestProperty("Connection", "close");

    // HTTP Response
    System.out.println("Status Line Code: " + socket.getResponseCode());
    System.out.println("Status Line Message: " +
    socket.getResponseMessage());
    System.out.println("Connector After");
    if (socket.getResponseCode() == HttpConnection.HTTP_OK) {

    in = socket.openInputStream();

    }

    } catch (Exception e) {

    }


    }

    SendAndreceiveData();


    }

    private void SendAndreceiveData() {

    try {

    int ch;
    while ((ch = in.read()) != 0) {
    // data_Store = in.read();
    string = string + (char) ch;
    System.out.println(string);
    if ((char) ch == '\n')
    break;

    }

    if (!(string.equals(""))) {

    sub_Value = string.substring(value, value + 4);
    System.out.println("sub_Value::" + sub_Value);
    }

    if (sub_Value.equals("+OK ")) {
    if (!(CountOks == 5))
    CountOks++;

    if (CountOks == 1) {
    System.out.println("Inside the +ok" + CountOks);
    String user_Name = "USER girija\r\n";

    out.write(user_Name.getBytes()); //Exception

    //This is musu for me so any othe ideas are ther plz inform me




    } catch (Exception e) {
    e.printStackTrace();
    }
    }

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    9

    Default

    Welcome to the Java Forums.

    Please take note that you have posted to the wrong forum and I have taken the liberty to move it to the correct forum so that your topic gets the proper attention.

    Please make use of the [ code] [ /code] tags when posting- it makes it easier to read for those viewing your code.

    Lastly, please read the FAQ before you post again as you've made several infractions with your first post here.

    Thank you for your cooperation and understanding. Best of luck with your topic.

    Take care and see you around! :)
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •