×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    4

    Unhappy N70 java jsr-82 OBEX Problem

    Hi,

    I'm developing a J2SE server application to interoperate via OBEX Bluetooth with a J2ME application deployed into a Nokia N70.

    I've been following "BCExchanger" example, but I have several problems to execute put and get operations from the J2ME application.

    When I execute a put from the J2ME application, a connection is open in the J2SE server, but the onPut() method is never called in server, and when I execute a get from the J2ME application, the onGet() method is called in server, but I receive the following exception "java.io.IOException: Operation aborted".

    I'm using Bluecove implementation in the server side. And the same code (J2ME application) works fine in a Sony Ericsson W810 and in a Motorola v360 using the same server. So I'm think it is a problem of N70 device (perhaps permissions in MANIFEST.MF?)

    The code for the J2ME application:

    public void doSend(Transferable obj)
    {
    try
    {

    connection = (ClientSession) Connector.open(url);
    HeaderSet response = connection.connect(null);

    // Initiate the PUT request
    operation = connection.put(null);

    OutputStream out = operation.openOutputStream();

    byte[] vData = obj.getBytes();

    int vlen = vData.length;

    byte[] tmpBuf = new byte[vlen + 4];
    System.arraycopy(vData, 0, tmpBuf, 4, vlen);
    tmpBuf[0] = (byte) ((vlen >>> 24) & 0xff);
    tmpBuf[1] = (byte) ((vlen >>> 16) & 0xff);
    tmpBuf[2] = (byte) ((vlen >>> 8) & 0xff);
    tmpBuf[3] = (byte) ((vlen >>> 0) & 0xff);

    //sending data
    out.write(tmpBuf);

    out.close();
    int responseCode = operation.getResponseCode();


    operation.close();

    if (cancelInvoked) {
    throw new Exception("Cancel did not invoke any exception; throw exception then");
    }

    // send is done
    try {
    parent.setState(new IdleState(parent));
    } catch (Exception e){

    }
    }
    catch (Exception e1)
    {


    }
    finally {
    try { // finalizing operation
    operation.close();
    }
    catch (IOException e3) {

    }

    try { // sending DISCONNECT command
    connection.disconnect(null);
    connection.close();
    }
    catch (IOException e2){

    }
    }
    }


    public byte[] doGet(){
    byte[] vData=null;
    try{
    connection = (ClientSession) Connector.open(url);

    HeaderSet response = connection.connect(null);
    operation = connection.get(null);

    InputStream in = operation.openInputStream();

    byte[] fullResult = null;

    {
    byte[] buf = new byte[256];
    ByteArrayOutputStream bout = new ByteArrayOutputStream(2048);

    for (int len = in.read(buf); len >= 0; len = in.read(buf)){
    bout.write(buf, 0, len);

    }

    fullResult = bout.toByteArray();
    }


    ByteArrayInputStream bin = new ByteArrayInputStream(fullResult);
    DataInputStream din = new DataInputStream(bin);

    int size = din.readInt();
    vData = new byte[size];
    din.read(vData);


    // End the transaction
    in.close();
    int responseCode = operation.getResponseCode();
    operation.close();

    if (cancelInvoked) {
    throw new Exception("Cancel did not invoke any exception; throw exception then");
    }



    }catch (Exception e1){

    }finally {
    try { // finalizing operation
    operation.close();
    } catch (IOException e3) {

    }

    try { // sending DISCONNECT command
    connection.disconnect(null);
    connection.close();
    } catch (IOException e2)
    {
    // Ignore, disconnecting anyway

    }


    }
    return vData;
    }


    The code for the server (J2SE application):

    public class ServerThread extends ServerRequestHandler implements Runnable{

    final private String uuid = "ed495afe28ed11da85d900e08161165f";
    final private String serverURL = "btgoep://localhost:" + uuid;
    private SessionNotifier notifier = null;
    private Connection con = null;

    private Thread connectionsThread;



    public ServerThread(){
    connectionsThread=new Thread(this);
    connectionsThread.start();
    }

    public int onGet(Operation op) {
    System.out.println("onGet");
    try {

    OutputStream out = op.openOutputStream();

    Event ev=new Event("server","server");

    byte[] vData = ev.getBytes();

    int vlen = vData.length;

    byte[] tmpBuf = new byte[vlen + 4];
    System.arraycopy(vData, 0, tmpBuf, 4, vlen);
    tmpBuf[0] = (byte) ((vlen >>> 24) & 0xff);
    tmpBuf[1] = (byte) ((vlen >>> 16) & 0xff);
    tmpBuf[2] = (byte) ((vlen >>> 8) & 0xff);
    tmpBuf[3] = (byte) ((vlen >>> 0) & 0xff);

    out.write(tmpBuf); // sending data

    System.out.println("##################");
    System.out.println("enviado "+(tmpBuf[0] << 24) + ((tmpBuf[1] & 0xFF) << 16) + ((tmpBuf[2] & 0xFF) << 8) + (tmpBuf[3] & 0xFF));
    System.out.println("##################");

    //Aqui se la pega
    op.close();
    //out.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    return ResponseCodes.OBEX_HTTP_OK;
    }

    public int onPut(Operation op) {
    System.out.println("onPut");
    try {
    InputStream in = op.openInputStream();
    byte[] fullResult = null;
    {
    byte[] buf = new byte[256];
    ByteArrayOutputStream bout = new ByteArrayOutputStream(2048);
    for (int len = in.read(buf); len >= 0; len = in.read(buf))
    bout.write(buf, 0, len);
    fullResult = bout.toByteArray();
    }
    ByteArrayInputStream bin = new ByteArrayInputStream(fullResult);
    DataInputStream din = new DataInputStream(bin);


    int size=din.readInt();
    byte[] vData = new byte[size];
    din.read(vData);

    op.close();
    //in.close();

    Event ev=new Event();
    ev.fillObject(vData);
    System.out.println("Recibido "+ev.getFriendlyName());
    }catch(Exception e){
    e.printStackTrace();
    }
    return ResponseCodes.OBEX_HTTP_OK;
    }

    public synchronized void onDisconnect(HeaderSet request, HeaderSet reply) {
    super.onDisconnect(request, reply);
    System.out.println("onDisconnect");
    notify();// stops waiting in run()
    }

    public synchronized void run() {
    try{
    LocalDevice local = LocalDevice.getLocalDevice();
    local.setDiscoverable(DiscoveryAgent.GIAC);
    }catch (Exception e){
    // catching notifier exception
    //listener.onServerError();
    e.printStackTrace();
    return;
    }

    try{
    notifier = (SessionNotifier) Connector.open(serverURL);
    }catch (IOException e2){

    }

    String finBucle=new String();
    do{
    try{
    con = notifier.acceptAndOpen(this);

    System.out.println("new remote connetion");
    wait();
    System.out.println("remote connection closed");

    try{
    con.close();
    }catch (IOException e0){
    e0.printStackTrace();
    }
    }catch(Exception e){
    e.printStackTrace();
    }


    try{
    System.out.println("Continue (y/n)");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    finBucle = br.readLine();
    }catch(Exception e){
    e.printStackTrace();
    }

    }while(!finBucle.equals("n"));

    try{
    notifier.close();
    }catch(Exception e){
    e.printStackTrace();
    }

    }


    }

    Thanks in Advance.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Do you use your private long UUID on all devices? Or how does you service look like? By the way, vB has a code tag.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    4

    Re: N70 java jsr-82 OBEX Problem

    Hello,

    I'm using the following url + uuid in server side like url:

    "btgoep://localhost:" + "ed495afe28ed11da94d900e08161165f"


    and in client side for the service discovery:

    UUID[] uuids = new UUID[1];
    uuids[0] = new UUID("ed495afe28ed11da94d900e08161165f",false);
    agent.searchServices(null, uuids, device, this);

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    I guess you use Nokia’s java.obex package, right? I cannot comment on your problem directly, however, I would forget that one as fast as possible (for me it was far too buggy) and use your own one.

  5. #5
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: N70 java jsr-82 OBEX Problem

    checkout this link
    thanks,
    jitu_goldie..

    KEEP TRYING..

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    4

    Re: N70 java jsr-82 OBEX Problem

    Hi!

    Now it works, the problem was the Nokia’s java.obex package (Thank you Traud), including java.obex of Avetana implementacion (http://sourceforge.net/projects/avetanaobex/) in the client applitacion and using its classes for the OBEX connection there is no problem in the communication among server and client.

Similar Threads

  1. Problem adding Java ME MIDP Platform Emulator in NetBeans 6.5
    By furau in forum Mobile Java Tools & SDKs
    Replies: 4
    Last Post: 2010-11-26, 09:42
  2. Problem running NetworkDemo in Java ME SDK 3.0
    By gz19880228 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2009-05-10, 10:58
  3. OBEX problem! IllegalStateException:add Notify when already added
    By backspace in forum Mobile Java General
    Replies: 1
    Last Post: 2007-07-26, 17:29
  4. Nokia N70 - HTTP POST problem
    By heuven in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-04-13, 15:48
  5. Problem with N70
    By MohammadHendy in forum Symbian User Interface
    Replies: 6
    Last Post: 2006-04-20, 10:57

Posting Permissions

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