BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 11-14-2007, 03:45 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
Red face A problem of receiving data from server

Please Login to Remove!

Hi, everyone:

I want to receive data from server again and again in a while loop , but it seems some strange things happen. The server has sent the data through a socket, and the data format is "data length + data". And if the client connect to the server by a socket connection, the server will send the data to client.

the receiving codes are :
Code:
byte[] buf = new byte[4];
SocketConnection sock = (SocketConnection)Connector.open(server.toString(),Connector.READ);
DataInputStream inStream = sock.openDataInputStream();                
while(true)
{                                   
   count = inStream.read( buf,0, buf.length);                              
   if ( (count == 4) && (buf != null) )
   {                        
       dataLength = bytes2int(buf); //analyze the package head 
    }
   imageData = new byte[dataLength];                                       
   count = inStream.read(imageData,0,imageData.length);   
   //process the imageData
   .........
}
And during the testing, I find that the program runs well at the beginning, but the dataLength will occur error sometimes, it's a big value and this makes the failture of the "new byte[dataLength]". From the log file of the server, I know that the datalength sent by server is OK.

So does anyone have any ideas?Thank you very much!
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

McMASTER-CARR SUPPLY CO. THERMOCOUPLE JAA3-F3A036-3BXZ NEW
$20.0
McMASTER-CARR SUPPLY CO. THERMOCOUPLE JAA3-F3A036-3BXZ   NEW pictureLot of 4 Hanna Instruments HI935005 K-Thermocouple Thermometer w/Probe, Working
$59.99
Lot of 4 Hanna Instruments HI935005 K-Thermocouple Thermometer w/Probe,  Working pictureOmega TT-T-20-TWSH-SLE 200 Foot Thermocouple Wire Quantity Available
$55.0
Omega TT-T-20-TWSH-SLE 200 Foot Thermocouple Wire Quantity Available picture9.8 Ft 800C Probe Thermocouple Temperature Sensor Cable 8 mm Thread Diameter New
$13.83
9.8 Ft 800C Probe Thermocouple Temperature Sensor Cable 8 mm Thread Diameter New picturePyco Thermocouple 02-3046-13-6.6 Temperature Probe
$100.0
Pyco Thermocouple 02-3046-13-6.6 Temperature Probe picture






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