×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    4

    Smile Urgent Help Required

    hi iam sending this code the problem is that when i run this code and send a byte string to a server than server replies the first time accurately and the response it displayed properly but when i send the new string the second time and wait for a server response nothing happens and when i try to print the new message still the old response gets printed.
    i think there is something wrong with the way iam printing the response using the InputStream class . Following is the code in midlet(j2me)

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.StreamConnection;
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    import java.util.*;



    public class HttpTest extends MIDlet {
    public void startApp() {
    try
    {
    String url = "socket://" +"messenger.hotmail.com"+ ":" +1863;
    SocketConnection sc = (SocketConnection) Connector.open(url);
    InputStream in = sc.openInputStream();
    OutputStream out = sc.openOutputStream();
    out.flush();
    String str="VER 1 MSNP8 CVR0\r\n";
    out.write((str+ "\r\n").getBytes());

    out.flush();
    StringBuffer sb = new StringBuffer();
    int c = 0;
    while (((c = in.read()) != -1) ) {
    sb.append((char) c);
    }
    System.out.println(sb.toString());




    String str1="CVR 2 0x0409 win 2000 i386 MSNMSGR 5.0.0544 MSMSGS cybrog_ed@hotmail.com\r\n";

    out.write((str1+ "\r\n").getBytes());

    String str2="USR 3 TWN I cybrog_ed@hotmail.com\r\n";
    out.write((str2+ "\r\n").getBytes());

    int d = 0;
    while (((d = in.read()) != -1) ) {
    sb.append((char) d);
    }
    System.out.println(sb.toString());







    }
    catch(Exception e)
    {
    }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    }

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Urgent Help Required

    hi cybrog_ed,
    welcome aboard!


    isn't your server connection made only once application per applicatoin lifetime? (within startApp() method),

    regards,
    Peter

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    4

    Smile Re: Urgent Help Required

    Quote Originally Posted by peterblazejewicz
    hi cybrog_ed,
    welcome aboard!


    isn't your server connection made only once application per applicatoin lifetime? (within startApp() method),

    regards,
    Peter

    Yes you are right but as long as the startApp() method is running it means that the method is still in focus and should response. i mean when i send the first string the response comes accurately but for the second time the MSN server should send another string iam still in the startApp() method than i dont under stand what is the problem. iam confused at this point plese tell me what should i do.
    thanks alot.

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    4

    Smile Re: Urgent Help Required

    Quote Originally Posted by peterblazejewicz
    hi cybrog_ed,
    welcome aboard!


    isn't your server connection made only once application per applicatoin lifetime? (within startApp() method),

    regards,
    Peter
    ----------------------------------------------

    even if i place the code in a separate function and call it from the constructor still the problem is there and is not solved the code below is what i tried after u replied but the problem is still there the second response never gets printed and everything stops
    --------------------------------

    /*
    * HttpTest.java
    *
    * Created on July 3, 2006, 9:28 PM
    */

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.StreamConnection;
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    import java.util.*;



    public class HttpTest extends MIDlet {
    public HttpTest()
    {
    startRunning();
    }

    public void startApp() {

    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    public void startRunning()
    {
    try
    {
    String url = "socket://" +"messenger.hotmail.com"+ ":" +1863;
    SocketConnection sc = (SocketConnection) Connector.open(url);
    InputStream in = sc.openInputStream();
    OutputStream out = sc.openOutputStream();
    out.flush();
    String str="VER 1 MSNP8 CVR0\r\n";
    out.write((str+ "\r\n").getBytes());

    out.flush();




    String str1="CVR 2 0x0409 win 2000 i386 MSNMSGR 5.0.0544 MSMSGS cybrog_ed@hotmail.com\r\n";

    out.write((str1+ "\r\n").getBytes());
    StringBuffer sb = new StringBuffer();
    int c = 0;
    while (((c = in.read()) != -1) ) {
    sb.append((char) c);
    }
    System.out.println(sb.toString());





    }
    catch(Exception e)
    {
    }
    }
    }

Similar Threads

  1. Urgent Cardphone Driver required
    By bilgict@bp.com in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 16:09
  2. urgent info required - Emulator supporting bluetooth
    By sujoydas in forum Bluetooth Technology
    Replies: 0
    Last Post: 2004-01-10, 13:40
  3. NOKIA, Sim ToolKit Class for Nokia 3410 URGENT RESPONSE REQUIRED!!!!
    By HellBlade45 in forum Mobile Java General
    Replies: 0
    Last Post: 2003-05-03, 11:29
  4. Wap GW required in connections with 6310i? (urgent)
    By noxo in forum Mobile Java General
    Replies: 1
    Last Post: 2002-06-14, 12:32

Posting Permissions

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