| Reply | « Previous Thread | Next Thread » |
|
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;
}
......
|
|
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());
}
![]() 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:
- 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 |
|
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |