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) {
}
}

Reply With Quote


