J2ME SocketConnection Help
Posted: Tue Aug 17, 2010 4:41 pm
I have been trying to connect to MSN Authentication server as the feasibility study phase of building my own MSN client for Java Mobiles. The Initial command for the server is like "VER 0 MSNP8 MSNP7 MNSP6 CVR0". This is to negotiate the MSN protocol used for the communication. And the Java Implementation simply does not work for me. I have been trying whole say.
And following is the C# implementation. It works till it tells me the Notification Server IPs.
So, I like to get some help from a Guru...

Code: Select all
try{
SocketConnection con=
(SocketConnection) Connector.open("socket://messenger.hotmail.com:1863");
//Output and input streams opened....
OutputStream output =con.openOutputStream();
output.flush();
output.write("VER 0 MSNP8 CVR0".getBytes());
output.flush();
InputStream in =con.openInputStream();
int inputChar=in.read();
while ( inputChar!=-1) {
sbf.append((char)inputChar);
inputChar=in.read();
}
}
catch(ConnectionNotFoundException error)
{
Alert alert = new Alert(
"Error", "Cannot access socket.", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
catch(Exception ex){}
Code: Select all
TcpClient client = new TcpClient();
try
{
client.Connect("messenger.hotmail.com", 1863);
if (client.Connected)
{
textBox1.AppendText("Client is connected\n");
NetworkStream networkStream = client.GetStream();
StreamWriter streamWriter = new StreamWriter(networkStream);
StreamReader streamReader = new StreamReader(networkStream);
streamWriter.WriteLine("VER 0 MSNP8 MSNP5 CVR0");
streamWriter.Flush();
textBox1.AppendText(streamReader.ReadLine()+"\n");
streamWriter.WriteLine("CVR 1 0x0409 win 5.1 i386 MSNMSGR 2.1.6000 MSMSGS herat**@hotmail.com");
streamWriter.Flush();
textBox1.AppendText(streamReader.ReadLine() + "\n");
streamWriter.WriteLine("USR 2 TWN I herat**@hotmail.com");
streamWriter.Flush();
textBox1.AppendText(streamReader.ReadLine() + "\n");
}
else
{
textBox1.AppendText("Client is not connected\n");
}
}
catch (Exception)
{
throw;
}