×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    48

    Angry OBEX Programming

    Hello.I wrote two apps.One client application and one server application that exchange file using the obex protocol.

    I used the bluetooth and obex optional pakages for the client application that runs on a mobile and avetanabluetooth for the server application that runs on my pc.

    If i exchange small files like text files everythings works right.
    If i try to exchange a bigger file,like a movie,i get an exception when i open the OutputStream on the client application and begin to read.

    I get : Maximum Packet Size Exceeded 1027 > 1024 !!!!

    What's that? The Obex implementation should handle packet size by itself.Shouldn't it? How could i do?Is there a a way to set the MTU within a obex connection??

    pleas help me!Thank you

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    67

    Re: OBEX Programming

    Please post some code to look at. Without code it's hard to guess what's wrong ...

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: OBEX Programming

    These are the pieces of code involved:

    CLIENT:


    op = conn.get(head);
    midlet.mainForm.append("Get request done\n");
    DataInputStream in = op.openDataInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte data = in.readByte();
    midlet.mainForm.append("Trasferring\n");
    while (data != -1) {
    out.write((byte)data);
    data = in.readByte();
    }
    in.close();
    op.close();
    ByteArrayInputStream bis=new ByteArrayInputStream(out.toByteArray());
    out.close();

    _____SERVER___


    byte[] data=cMan.getResource(name); //got the data from a file
    DataOutputStream os=op.openDataOutputStream();
    System.out.println("Streaming resource..");
    os.write(data,0,data.length);
    os.flush();
    System.out.println("Data sent");
    os.close();
    op.close();

    When the server does: os.write(data,0,data.length) an exception at the client code happen when it does byte data=in.readByte();
    For small data like a String the exception isn't thrown.

    Max Packet Size Exceeded 1027 > 1024.

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    67

    Re: OBEX Programming

    Try sending smaller chunks of data, e.g.:

    ClientSession cs = (ClientSession) OBEXConnector.open(btUrl);
    HeaderSet hs = cs.connect(cs.createHeaderSet());
    hs.setHeader(HeaderSet.NAME, filename);
    hs.setHeader(HeaderSet.TYPE, "text/plain"); // adjust this to your needs
    hs.setHeader(HeaderSet.LENGTH, new Long(data.length) );

    Operation po = cs.put(hs);
    java.io.OutputStream os = po.openOutputStream();

    int of=0;
    do{
    int le = 64;
    if(le+of>data.length) le=data.length-of;
    os.write(data,of,le );
    os.flush();
    of+=le;
    }while(of<data.length);

    po.close();
    cs.disconnect(null);
    cs.close();

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: OBEX Programming

    mmm.the problem is that the server send the file to the client.
    The client send a get request to the server and the server open the outputstream and write data to the client.
    In that moment the exception occurs at the client.I tried to read smaller chunks but the exception occurs before reading data.I think it occurs at the transport layer when data from the server arrives.
    Anyway for the client i don't have OBEXConnector cause i use the obex package from sun that i've on the phone.

    On the server i use avetanaBluetooth and I initialize the server in this way:

    UUID uuid = new UUID("8216", true);
    String url = "btgoep://localhost:" + uuid + ";name=FabioObexServer;authenticate=false;master=false;encrypt=false";

    SessionNotifier sn = (SessionNotifier)Connector.open(url);
    ConnectionManager cMan=new ConnectionManager(); //the handler
    sn.acceptAndOpen(cMan);

    When I do a request for a content the server creates the data and writes it into the outputstream.
    If in the client i don't make any reading operation nothing happen.
    If i only read a byte from the inputstream i get the exception.
    I can't understand why if i read a small document of 1Kb it works fine.!!!!
    Last edited by Paranoid_Android; 2006-06-23 at 15:58.

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    67

    Re: OBEX Programming

    Ok. What I wanted to say was:

    ___SERVER_______

    byte[] data=cMan.getResource(name); //got the data from a file
    DataOutputStream os=op.openDataOutputStream();
    System.out.println("Streaming resource..");
    //os.write(data,0,data.length);
    //os.flush();

    int of=0;
    do{
    int le = 64;
    if(le+of>data.length) le=data.length-of;
    os.write(data,of,le );
    os.flush();
    of+=le;
    }while(of<data.length);



    System.out.println("Data sent");
    os.close();
    op.close();

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: OBEX Programming

    Done it..always the same exception..I'm going crazy!!
    As soon as i read a byte in the client the exception occurs..even if i send data in smaller chunks like u suggested me.

  8. #8
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    67

    Re: OBEX Programming

    I really thought it would help. I don't have another idea right now. Sorry.

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    On OBEX connect you get the maximum possible sizes for each OBEX message. Read those and then send not more than this in one OBEX message. JSR-82 does not handle issuing several PUTs or GETs required for such a case. You have to issue several PUTs or GETs for larger data.

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: OBEX Programming

    mm.I can't find how to get this massimum message length!!
    Anyway how can I do the things you said?When I send a get request I specify the filename.How can I do several get requests for chunks of file?

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Sorry I was wrong, because I use my own OBEX stack rather than the internal ones of Nokia or Avetana. The JSR-82 OBEX specification abstracts this maximum size thing. When you receive exceptions with segmenting in the native implementation, you have to go for your own OBEX stack …

    However, in your case I guess there might be a bug in Avetana's implementation as your client reports this issue. It looks like Avetana has misclaculated the data length: 1027. In OBEX the whole packet in the content + opcode + length. As the opcode+length is three byte long, you get 1024 +3 = 1027. Use another OBEX stack on your PC and/or ask Avetana about support. Or even better have a look at their source and fix it for all!

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: OBEX Programming

    Ok!Thank u very much.I will try to fix the bug or maybe i'll try to use bluecove with avetanaobex instead of avetanabluetooth with obex.

  13. #13
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    138

    Re: OBEX Programming

    Hello:

    I have seen this thread and perhaps you can help me. I have already implemented a device hardware that is listening to reception of files by Bluetooth OBEX. If I send it files manually (from my Bluetooth menu, In my phone, "send this file...Bluetooth", "Searching devices"..etc), it runs ok.


    What I need now is, in my phone, create a application that allows me to send files (smaller of 1Kb) to the device. The problem is that I only know the “friendly name” and the "MAC address" of the device.


    I've downloaded the Avetana OBEX, and I've created a project, with one class: OBEXTest.java.

    In the 37 line I've changed the MAC of the 6600 device example for my device:

    adrTextField = new TextField ("Address", "btgoep://000780810cfb:2", 30, TextField.URL);

    I don't know exactly what does the ":2" but I change this number from "0" to "10" and nothing happens. I push "put", "offer"...buffff all...


    Somebody can help me? … I am very inexperienced, so if anybody can paste some code, it will be helpfull.

    Thanks
    Last edited by Pepper_91; 2006-06-29 at 12:33.

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Please read the Bluetooth API for Java (JSR-82) documentation. Not only the Javadoc but the specification, too. Then please, please, please do proper device and service discovery which is explained in most detail in the specification.

Similar Threads

  1. opp and OBEX
    By znrabbit in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-11-28, 07:44
  2. SyncML over OBEX and Bluetooth
    By HWM in forum OMA DM/DS/CP
    Replies: 13
    Last Post: 2006-05-19, 18:47
  3. 3650, OBEX and Linux
    By jjaakkol2 in forum Symbian
    Replies: 0
    Last Post: 2003-09-22, 01:14
  4. SIM Programming
    By arspeiser in forum General Messaging
    Replies: 1
    Last Post: 2003-02-27, 08:23
  5. OBEX format over Nokia 7650 Vs ET39
    By stage_bt in forum Bluetooth Technology
    Replies: 1
    Last Post: 2002-10-16, 10:03

Posting Permissions

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