You Are Here:

Community: Developer Discussion Boards

#1 Old bluetooth buffer overflow - 2006-09-11, 13:59

Join Date: Sep 2006
Posts: 3
santax
Offline
Registered User
Hi,

i'm developing a server/client application that sends a file from a pc (PC1) using bluetooth to a mobile phone that receives it and instead of storing, it sends the data to another pc (PC2) using 3G network by opening a TCP socket. this last pc stores the data and make it readable (this pc has a fixed IP.

overall, it is fine, mostly. the problem (i think) is that the phone receives more data of wich it can process. the code line at the receive part only sends the data "stored" in the byte array to the pc2, but at some moment the phone stops receiving data eventhough the connection continues.

to solve this problem, i introduced a delay everytime pc1 sends a package wich is 512 Bytes.
variables are:
*bluetooth packet size (MTU). right now is 512 Bytes but i need it bigger.
*file size. the bigger it is, the higher the delay i have to introduce in order to receive all packets and the byteArray won't stuck.

i haven't been able to find out what to do, perhaps the processing speed of the phone isn't as big as the pc1's. is there a way to modify this?? or am i totally lost?? i'm working with a Nokia n70 which has a Symbian OS version 8.1a.

please, any help would be welcome!!!
thanks in advanced.


here's a piece of the code:

Code:
//program running on the phone

.........
  try{
        	localDevice.setDiscoverable(DiscoveryAgent.GIAC);
        	L2CAPConnectionNotifier notifier = (L2CAPConnectionNotifier)Connector.open("btl2cap://localhost:" + "3B9FA89520078C303355AAA694238F08;ReceiveMTU=512;TransmitMTU=512");
        	conn= notifier.acceptAndOpen();
             new Thread(new Runnable(){
                public void run(){
                    startReceiver();
                }
            }).start();
            status.setText("File Received!");
            display.setCurrent(mainUI);
        } catch(IOException ioe) {
            status.setText("IOException: " + ioe.toString());
        }
//..........

public boolean startReceiver(){
//........

try{
       	socketOut = (SocketConnection)Connector.open("socket://"+URL+portOut);
            status.setText("Connection stablished to Server");
            OutputStream os = socketOut.openOutputStream();
            
        }
        catch(java.io.IOException ioe){
       }
        
        try {
        	id = conn.getReceiveMTU();//size of the bluetooth packet
        	byte[] inBuf = new byte[(3*id)] ;//input buffer
  
		    while (n==0)// 
                {
                    //cont1++;
                    status.setText(" first n=0: "+cont1);
                    n = conn.receive(inBuf);
                    
                }
		    os.write(inBuf,0,n);
                cont++;
                mv=true;
                try {
                    while(mv==true) {
                        id=conn.getReceiveMTU();
                        n = conn.receive(inBuf);
                        while (n==0) {
                            cont1++;
                            status.setText("n=0: "+cont1);
                            n = conn.receive(inBuf);
                        }
                        if (n>0) {
                        	os.write(inBuf, 0,n);
                           	cont++;
                            status.setText("writing: "+cont+"\nn :"+n+ "\n0's: "+cont1+"\nMTU: "+id);
                        }
                    }
                } catch (IOException e) {
                    
                }
                
                os.close();
                socketOut.close();
            status.setText("file written.\npackets: "+cont+"\nn :"+n+ "\n0's: "+cont1+"\nCx closed");
            return true;
            
        } catch(IOException ioe){
            status.setText("IOException: "+ioe.getMessage()+"\nready: "+ready);
            return true;
        }catch (Exception e) {
            String s = "Can not create file '";
            if (e.getMessage() != null && e.getMessage().length() > 0) {
                s += "\n" + e;
            }
            Alert alert = new Alert("Error!", s, null, AlertType.ERROR);
            alert.setTimeout(Alert.FOREVER);
            Display.getDisplay(this).setCurrent(alert);
            // Restore the commands that were removed in commandAction()
            Display.getDisplay(this).getCurrent().addCommand(creatOK);
            Display.getDisplay(this).getCurrent().addCommand(gobackCommand);
            return true;
        }
        }catch(Exception e){
        	 return true;
         }
        
......
Reply With Quote

#2 Old Re: bluetooth buffer overflow - 2006-09-14, 00:06

Join Date: May 2006
Posts: 11
Location: Leiden, NL
Send a message via MSN to micmail Send a message via Skype™ to micmail
micmail
Offline
Registered User
Santax,
I would like to help but I cannot understand your code very well (for sure it's my lack of knowledge).
For example, this:
Code:
 try{
        	localDevice.setDiscoverable(DiscoveryAgent.GIAC);
        	L2CAPConnectionNotifier notifier = (L2CAPConnectionNotifier)Connector.open("btl2cap://localhost:" + "3B9FA89520078C303355AAA694238F08;ReceiveMTU=512;TransmitMTU=512");
        	conn= notifier.acceptAndOpen();
             new Thread(new Runnable(){
                public void run(){
                    startReceiver();
                }
            }).start();
            status.setText("File Received!");
            display.setCurrent(mainUI);
        } catch(IOException ioe) {
            status.setText("IOException: " + ioe.toString());
        }
doesn't even seem belonging to the Nokia SDK to me

BTW, IMHO it is not a speed problem, since the N70 has a CPU ARM-9 @ 220 MHz and runs Symbian, which is quite fast compared to PC OSs.
Just a couple of questions:
- why are you using 'threads' and 'try-catch' mechanisms (this is respectively not reccomended and not supported in Symbian, you should maybe use Active Objects)? I read on the SDK help:
Quote:
Symbian OS provides its own exception handling mechanisms. C++ exception handling (try, catch and throw) is not used because:

compiler support for C++ exception handling was unavailable or inadequate at the time of Symbian OS's design

Symbian OS exception handling is specialised for use with other Symbian OS conventions (C and T classes, 32-bit integer error codes), allowing lower overheads than for C++ exception support

Existing C++ programs for other platforms that use exception handling must be modified before they can be used.

Note that the cleanup and two-phase construction idioms that are part of Symbian OS exception support would still be needed if C++ exception handling were used.
- using the "new" operator is, again, not reccomended (do you allocate 3*512 bytes? Do you destroy the array after?). I would suggest HBufC8 with Des() in 2nd ED and RBuf8 in 3rd ED.
- from "while(mv==true)" you exit using an exception? Wasn't there another option?

I hope someone better than me will add some more useful comments.. sorry.

Good luck,
Michele
Reply With Quote

#3 Old Re: bluetooth buffer overflow - 2006-09-15, 12:08

Join Date: Sep 2006
Posts: 3
santax
Offline
Registered User
thanks for replying.

well, i'm not a java expert, so i try to do my best on the code and since the application should run on most of all devices, not only Symbian, i didn't check its manual.

to write the code i'm using Eclipse 3.1.2 and the Sun WirelessToolkit 2.2.

i don't know if a i didn't understand your reply but i'm developing this on java, (i say this 'cause the Symbian quotes spoke about C++) however, i'll follow your advice concerning on the try-catch, handling exceptions and destroying the array.

thank you very much for your time and if you want to help me on this code, i'd be grateful.

thanks, Juan
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP !!! Bluetooth SPP speed : DataInputStream overflow? rikow Mobile Java General 1 2006-05-19 16:54
CMdaAudioOutputStream Not working with EXEDLL target fnagaton General Symbian C++ 6 2005-10-03 06:51
Dialog's clipping area (again). Nokia experts, please help synov Symbian User Interface 0 2004-06-26 15:35
how to set the send/recv buffer size of L2CAP sockets in Bluetooth gpalvia Bluetooth Technology 0 2004-03-26 08:03
Nokia 7650 support Bluetooth audo? ovjo12 Bluetooth Technology 5 2003-07-17 19:50

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia