|
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();
}
}
|