BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 07-30-2007, 02:41 AM   #1 (permalink)
Thumbs Must Hurt
Join Date: Jun 2007
Model: 8800
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!

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;

SocketConnection sock = (SocketConnection) );
outStream = sock.openDataOutputStream();
inStream = sock.openDataInputStream();

//send message to server
if (n < 10)

buffer1.delete(0, buffer1.length());
buffer1.append("this is the ");
buffer1.append( n );
buffer1.append("th times send message!");

//read the message

int len = 0;
byte[] outByte = new byte[1000];
while ((len = != -1)
System.out.println(new String(outByte));
} //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 = != -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, so can anyone tell me why?

Thank you very much!

Last edited by streamh : 07-30-2007 at 02:43 AM.
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

APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD
APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD   picture

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.