.NET Components for Mobility

Exception when a device rejects a file transference

Last post 07-10-2008 6:29 AM by Vicente. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-01-2008 8:50 AM

    Exception when a device rejects a file transference

    Hi,

    I'm doing an application that sends files to several devices. I need to know if the request to send a file has timeout or if the receiver has rejected it. So far this is what I'm doing:

    try
    {
     ObexSessionConnection conn = null;
     conn = new UriObexSessionConnection("obex", deviceId.Address);

     conn.Connect();
     conn.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, Settings.Default.Transference_SendTimeout * 1000);
     conn.ObexClientSession.PutFrom(file, fileName, null, file.Length);
     conn.Close();

     status = TransferenceStatus.Success;
     isSendCompleted = true;
    }

    catch (SocketException se) // Socket send timeout
    {
     status = TransferenceStatus.Ignored;
     Logger.LogInformation(this, string.Format("Code {0}. Socket {1}. Native {2}.", se.ErrorCode, se.SocketErrorCode, se.NativeErrorCode));
    }

    catch (ObexResponseException ore) // Lots of different errors here
    {
     if (ore.ResponseCode == ObexResponseCode.Forbidden)
     {
      status = TransferenceStatus.Rejected;
     }

     else
     {
      status = TransferenceStatus.Error;
     }

    }

    catch (Exception ex) // This should never happen
    {
     status = TransferenceStatus.Error;
    }

    finally
    {
     if (file != null)
      file.Close();
    }

    If the request timesout or I reject it in my mobile phone, I always get a SocketException with exception code 10064 (HostDown). I've trying to search for other ways to be able to know when it's one situation or the other, but so far I have had no luck. Any idea or hint?

    Regards!

  • 07-03-2008 6:48 AM In reply to

    Re: Exception when a device rejects a file transference

    Hmm.  Firstly often OBEX servers often don't prompt the user until the receive is complete, for 32feet.NET's user guide:

    Behaviour from servers

    Most devices with an OBEX Server don’t return a different response code depending whether the user accepted the received object or rejected it.  In most cases the server actually only prompts the user after the complete object has been received.  This is the case for all the portable devices that I've seen; for instance PalmOS devices and Nokia mobile phones — they return an error code only if the object was too big to be received for instance.  One device that does prompt before the object is received is Windows XP etc: the user is prompted, which blocks the continuing transfer until the user replies.

    So I'd either expect an OK response -- if it doesn't prompt till completion, or a NotAllowed (for instance) if it did prompt. 

    What behaviour do you see when there's no timeouts set?

  • 07-03-2008 10:20 AM In reply to

    Re: Exception when a device rejects a file transference

    I know very little about Bluetooth and OBEX, but I've been doing some tests and talking with other people in the area that work on mobility, and the file doesn't seem to be transferred until the user accepts it (there's a very easy to see delay between the "Accept File" and "File Received" messages depending on the file size). We have tested with Windows Mobile smartphones (HTC), Nokia phones and Blackberries.

    Either way, when I take this line out:

    conn.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, Settings.Default.Transference_SendTimeout * 1000);

    I keep getting the same error as before. It seems that after around 40 seconds my Nokia phone automatically cancels the file transfer with error 10064 (rejecting the file gives me also error 10064). My timeout setting was 60 seconds, so I changed it to 20 seconds but the line seems to have no effect, as the phone cancels the file after 40 seconds instead of getting the timout at 20 seconds...

    So now I'm not sure what the line I put before is doing exactly (as it seems to be doing nothing), but at least the error messages from the phone seem to make sense now.

    Any other idea on how I could force a timeout after 20 seconds for example?

  • 07-10-2008 6:08 AM In reply to

    Re: Exception when a device rejects a file transference

    I'm not following the whole scenario, but to set a timeout you should set a receive timeout.  Unless the link has been dropped, or megabytes of data has been sent but not transferred, the send operation will complete quickly.  However if the OBEX server on the peer device is stuck etc, the the OBEX response packet won't be received.  Set both for safety but the receive timeout is more important.

    I'll add some more words to the Programmer's Guide on that subject.

  • 07-10-2008 6:29 AM In reply to

    Re: Exception when a device rejects a file transference

    Hi,

    the scenario is like this:

    • I have a windows service running on a Windows XP machine with a bluetooth doongle compatible with the Microsoft BT Stack. This service has a timer that raises an event every 30-45 seconds.
    • When that event is fired I use the BluetoothClient from the InTheHand library to discover bluetooth devices.
    • For each device I check if it's really a new device or I had seen it during the day.
    • If it's new I check if I have to send it a file with some information.
    • If I have to send the file I create a new thread and use the Brecham.OBEX library to send the file to the Bluetooth device.

    I'll try setting the receive timeout and post here with the results. Thanks for your time!

    Vicente

Page 1 of 1 (5 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.