BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 07-16-2007, 10:43 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default dataOuputStream closing to quickly?

Please Login to Remove!

hello there!

I have a problem where I'm sending some bytes to a dataOutputStream to a bluetooth serial port but not all bytes are being written before the stream is closed.

I'm making several writes of data and have tried flushing after every write and flushing again before closing but none of it helps.

I'm quite sure this is the problem anyway because if I leave the stream open (i.e. don't close it at all in the app) then all data gets written fine and I see the desired results on the bluetooth printer, however when I attempt to open a connection again I don't get anything...

Also, when I have the debugger attached to the bberry I get more bytes written to the port than otherwise (I presume as there's a larger overhead and everything runs more slowly so the connection gets closed slightly later than otherwise.

I've tried implementing a 'wait' (and catching the associated exception thrown), but I'm not 100% sure what I'm doing as I'm new to bberry development.

The wait part looks like :
//wait and close connection
long wait_time = 60000;
_dout.wait((long)wait_time);
System.out.println("Waiting to close connection...");
_dout.close();
_bluetoothConnection.close();
System.out.println("Connection closed...");

but it always generates an exception in this thread so I'm not really sure if I'm implementing it properly.

Any suggestions would be very much appreciated...

Regards,
Offline  
Old 07-23-2007, 10:13 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just in case anybody had the same problem (there were one or two on another forum), the solution was to implement a
Code:
try {
   sleep(milliseconds);
} catch(InterruptedException e) {
  //something here
}
Just after all my writing - works a treat! I find 5 seconds is enough - might try to fine tune it down...

Hope this helps someone...

Last edited by seekay : 07-23-2007 at 10:15 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

Fuel shut Off Solenoid for Kubota B2710 B2910 B3030 B7510 32721-60014
$52.9
Fuel shut Off Solenoid for Kubota B2710 B2910 B3030 B7510 32721-60014 pictureHFS 110v Ac or 12v Dc Electric Solenoid Valve Water Air Gas, Fuels N/c - 1/4",
$12.19
HFS 110v Ac or 12v Dc Electric Solenoid Valve Water Air Gas, Fuels N/c - 1/4Heavy Duty Solenoid from Contact Industries 1004-24B
$49.99
Heavy Duty Solenoid from Contact Industries 1004-24B picturePARKER 7341NAKDHNM0N0H111P3 LUCIFER SOLENOID VALVE *FACTORY SEALED*
$225.0
PARKER 7341NAKDHNM0N0H111P3 LUCIFER SOLENOID VALVE *FACTORY SEALED* pictureDema MPN: A418P Solenoid Valve 120v 50-60Hz 15w 150-PSI
$27.0
Dema MPN: A418P Solenoid Valve 120v 50-60Hz 15w 150-PSI picture






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