BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-30-2007, 03:41 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default A problem of receive data by socket

Please Login to Remove!

Hi,everyone:
these days, I'm working reveive data from server by socket ,but there is always a problem confuse me, can anyone give some advice?
The function ReceiveMessage is as follow:
public int ReceiveMessage(String UrlServer)
{
int n=1;//total send 10 times
StringBuffer buffer = new StringBuffer();
StringBuffer buffer1 = new StringBuffer();
DataOutputStream outStream = null;
DataInputStream inStream = null;
try
{
buffer.append("socket://");
buffer.append("172.16.229.198");
buffer.append(":");
buffer.append("4321");

SocketConnection sock = (SocketConnection)Connector.open(buffer.toString() );
outStream = sock.openDataOutputStream();
inStream = sock.openDataInputStream();

//send message to server
while(true)
{
//xxx36755;xxx20986;xxx25968;xxx25454;xxx65281;
if (n < 10)
{

buffer1.delete(0, buffer1.length());
buffer1.append("this is the ");
buffer1.append( n );
buffer1.append("th times send message!");
outStream.write(buffer1.toString().getBytes());
outStream.flush();
System.out.println(buffer1.toString());

++n;
//read the message

int len = 0;
byte[] outByte = new byte[1000];
while ((len = inStream.read(outByte)) != -1)
{
System.out.println(len);
System.out.println(new String(outByte));
}
}
else
{
break;
}
} //end while
return 1;
} // end try
catch(IOException io)
{
//throw io;
System.out.println("there is an error :" + io);
return 0;
}
}//end ReceiveMessage


The server is written by C++ and it receives the messages sent from client,
while it also sends the message to me according the received message.
The problem is :
when I debug the program, the program always stop at the sentence :while ((len = inStream.read(outByte)) != -1), and after about one minute it's catch an error which says the connection timed out!
I can see from the server screen that the messeage from client has been received, and the message to client has been sent, but my program stop at inStream.read(), so can anyone tell me why?

Thank you very much!

Last edited by streamh : 07-30-2007 at 03:43 AM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.