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
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 02: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

APPRX 25PC PIGGYBACK 128K BIT DYNAMIC RAM LOT - DIP16
$9.95
APPRX 25PC PIGGYBACK 128K BIT DYNAMIC RAM LOT - DIP16 picture10x Matsushita MN44164P-15A NMOS 65,536 X 1 Bit Dynamic Ram
$9.99
10x Matsushita MN44164P-15A NMOS 65,536 X 1 Bit Dynamic Ram picture1x OKI MSM2114L-3RS - 4K ( 1024x4 Bit ) nMOS Static RAM sRAM - IC PDIP-18
$5.25
1x OKI MSM2114L-3RS - 4K ( 1024x4 Bit ) nMOS Static RAM sRAM - IC PDIP-18 picture1x Hitachi HM6264LP-12 - 8192-word x 8-bit High Speed 120ns CMOS Static RAM
$5.95
1x Hitachi HM6264LP-12 - 8192-word x 8-bit High Speed 120ns CMOS Static RAM picture1x Intel P5164SL-10 - 64K (8K x 8) CMOS Static Ram SRAM - IC DIP-24
$6.96
1x Intel P5164SL-10 - 64K (8K x 8) CMOS Static Ram SRAM - IC DIP-24 picture






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