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

