×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    3

    midp processign speed receiving file

    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;
             }
            
    ......

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: midp processign speed receiving file

    hi,

    shouldn't we think of solving that using producer/consumer threads pattern? it seems like helpful solution for such implementation (two different threads - one for bluetooth "producer" and other for "socket" client acting as consumer)?

    regards,
    Peter

Similar Threads

  1. Tips on using NDS 1.1
    By mitts in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2006-01-18, 16:07
  2. Replies: 0
    Last Post: 2002-11-19, 08:25
  3. Http connection problem in 6310i
    By teahola in forum Mobile Java General
    Replies: 1
    Last Post: 2002-10-03, 18:46
  4. Jad File Attributes for Nokia Phones (MIDP)
    By yogesh2002 in forum Mobile Java General
    Replies: 1
    Last Post: 2002-08-15, 15:16
  5. "Class file size does not match" in Nokia 6310i MIDP SDK Beta 0.9
    By Jouster in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2002-07-13, 23:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×