Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
New Developer
Posts: 11
Registered: ‎11-23-2009
My Device: Not Specified
Accepted Solution

Listening to incoming messages from chat server

Hi all,

I am trying to connect to a chat server and send messages to known user id. I am able to connect to server and login and send a message to a user. But I am confused about how to listen to incoming messages.

 

Below is the code which I'm trying.. This code below is written in the run method of a class extending Thread.

 

final StreamConnection connection = (StreamConnection) Connector
 .open("socket://" + this.server + ":" + this.port,Connector.READ_WRITE);
DataOutputStream o = connection.openDataOutputStream();
DataInputStream i = connection.openDataInputStream();
this.writer = new XmlWriter(o);
if(!isLogin){
 this.login(); 
}
this.sendMessage();
int c;
while (true) {
    c = i.read();
    if (c == -1) {
	break;
    } else { 
	System.out.println(String.valueOf(((char) c)));
    }

 

 

I am trying this in 8330 Simulator.  Initially the xml output confirming the authentication is printed but after that i get the exception. 

 

net.rim.device.cldc.io.ippp.SocketBaseIOException: Connection Timed Out

 

Please can anybody help me understand whats wrong. I want to establish a connection so that instant messaging would be possible between the two users.

 

Thanks in advance,

baj

 

 

New Developer
New Developer
Posts: 11
Registered: ‎11-23-2009
My Device: Not Specified

Re: Listening to incoming messages from chat server

Any pointers, please?

New Developer
New Developer
Posts: 11
Registered: ‎11-23-2009
My Device: Not Specified

Re: Listening to incoming messages from chat server

Solved with the help of the below open source project:

http://sourceforge.net/projects/kvmjab/

Developer
Posts: 51
Registered: ‎07-15-2008
My Device: Not Specified

Re: Listening to incoming messages from chat server

hi,

 

I am facing the same problem .

 

It will be great if u put part of sample code to listen to messages coming from server.

 

Thanks

 

 

Developer
Posts: 51
Registered: ‎07-15-2008
My Device: Not Specified

Re: Listening to incoming messages from chat server

Hi,

 

anybody out there ???