Hi,
I am writing a MIPD 1.0 program for client side, using StreamConnection, which will communicate with a server. Server may send data at any time, for that purpose I wrote a method getMessage(), with help of Timer class which calls the getMessage() method every 1000 milli seconds. While calling the getMessage() method, if the server sends data, then it is working other wise it is blocking the whole system(i.e if no data has been sent when the getMesaage method is called). Here is the code of getMessage() method:
public String getMessage()
{
String str = "";
try
{
inputStream = streamConnection.openDataInputStream();
int ch;
while (true)
{
ch = inputStream.read();
b1.append((char) ch);
if(ch == 10) break;
}
str = b1.toString();
System.out.println("From Server : " + str);
b1 = b1.delete(0,b1.length());
}
catch(Exception e)
{
System.out.println("Error in receiving message : " + e);
}
return str;
}
Is there any way to read data from the server without blocking the system. At any time the client can send data to the server also.
I tried using the available() method, but in all cases it is returning 0.
- Suraj Deo


Reply With Quote

