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

NEW Cisco 8831 CP-8831-K9 VoIP Unified Expandable Conference Station Phone
$490.0
NEW Cisco 8831 CP-8831-K9 VoIP Unified Expandable Conference Station Phone pictureLOT OF 10 Cisco CP-7942G Unified IP Phone - voip phone - used
$120.0
LOT OF 10 Cisco CP-7942G Unified IP Phone - voip phone - used pictureLOT of 50 Cisco CP-7940G 7940G VoIP PoE IP Business PHONE w/ Handsets
$149.0
LOT of 50 Cisco CP-7940G 7940G VoIP PoE IP Business PHONE w/ Handsets pictureLOT OF 23 MITEL IP 5224 DUAL-MODE OFFICE BACKLIT VOIP PHONES
$100.0
LOT OF 23 MITEL IP 5224 DUAL-MODE OFFICE BACKLIT VOIP PHONES pictureJDSU Viavi DSAM-3600B xt Docsis 3.0 CATV Meter DSAM3600 VoIP Check - Big Battery
$1499.0
JDSU Viavi DSAM-3600B xt Docsis 3.0 CATV Meter DSAM3600 VoIP Check - Big Battery picture






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