.NET Components for Mobility

"IOError on socket." with 2.4.0.0 Beta

Last post 02-12-2010 11:32 AM by alanjmcf. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 01-21-2010 1:13 AM

    "IOError on socket." with 2.4.0.0 Beta

     Hello,
    I work on ACER F900 with in the InTheHand.Net 2.4.0.0 Beta in c#. I try to send files with OBEX from F900 to my computer. It work fine with files which size is between 1 to 9822 bytes. After 9822 (so 9823 bytes), I got an "IOError on socket." :
    Une requête d'envoi ou de réception de données n'a pas été autorisée, car le socket n'est pas connecté et (lors de l'envoi sur un socket datagramme en utilisant un appel sendto) aucune adresse n'a été fournie; ; WidcommRfcommStream_Closed
    ===> A request to send or receive data was not authorized, because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied; ; WidcommRfcommStream_Closed

    à InTheHand.Net.Bluetooth.Widcomm.Wid

    commRfcommStream.EnsureOpenForWrite()
    à InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommStream.BeginWrite(Byte[ buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
    à InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommStream.Write(Byte[ buffer, Int32 offset, Int32 count)
    à InTheHand.Net.Bluetooth.Widcomm.DecoratorNetworkStream.Write(Byte[ buffer, Int32 offset, Int32 count)
    à InTheHand.Net.ObexWebRequest.Disconnect()
    à InTheHand.Net.ObexWebRequest.GetResponse()
    à TestInTheHand.Form1.button1_Click(Object sender, EventArgs e)
    à System.Windows.Forms.Control.OnClick(EventArgs e)
    à System.Windows.Forms.Button.OnClick(EventArgs e)
    à System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
    à System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
    à Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
    à System.Windows.Forms.Application.Run

    I use
    InTheHand.Net.Personal.dll 2.4.0.0 (from 32feet.NET 2.4_0616_beta)
    32feetWidcomm.dll 13 312 bytes (from 32feet.NET 2.4_0616_beta)
    VS 2008
    the device is Windows Mobile 6 Professional Device
    this is the code I use :
    private void button1_Click(object sender, EventArgs e)
    {
    String CurrentDirectory = GetCurrentPath();
    String Filename = CurrentDirectory + @"\testfile_{0}.txt";
    String NewFilename = String.Empty;
    FileStream fs = null;
    BinaryWriter bw = null;
    Byte[ Buffer;
    System.Uri uri = null;
    ObexWebRequest request = null;
    Cursor.Current = Cursors.WaitCursor;
    int Start = int.Parse(TxtStart.Text);
    int End = int.Parse(TxtEnd.Text);
    int Step = int.Parse(TxtStep.Text);
    for (int NbBytes = Start; NbBytes < End; NbBytes += Step)
    {
    Buffer = new Byte[NbBytes];
    StringBuilder sb = new StringBuilder();

    NewFilename = sb.AppendFormat(Filename, NbBytes).ToString();
    fs = new FileStream(NewFilename, FileMode.Create, FileAccess.ReadWrite);
    bw = new BinaryWriter(fs);
    bw.Write(Buffer);
    bw.Close();
    fs.Close();

    uri = new Uri("obex://" + "00190E02CFC4" + "/" + Path.GetFileName(NewFilename));
    request = new ObexWebRequest(uri);
    request.ReadFile(NewFilename);

    ObexWebResponse response = (ObexWebResponse)request.GetResponse();
    response.Close();
    File.Delete(NewFilename);
    }
    Cursor.Current = Cursors.Default;
    }


    Thanks !
  • 01-21-2010 3:55 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    So we see that the remote device closed the connection. What we see here is actually partly caused by a bug in ObexWebRequest.  I had not personally looked at the OBEX classes until recently, and have now fixed many bugs and flaws in them. One (bug 23462) I fixed was that ObexWebRequest will always attempt to send a DISCONNECT packet, even if an error occurred earlier -- and the connection has likely been closed!  That's what's happening here some error occurred -- which might have useful information -- and the connection closed, but we cause an error by writing to the connection and thus lose the first error.  If you want, you can compile a version from the code repository which has this fixed, however....

    Maybe something is wrong with the content of the file so the server returns an error/closes?  I don't understand what you're trying to send, but from my reading of the code you are sending a pile of zero bytes.  It seems a new byte array (Buffer) is created, it is not written to, so it full of zeros, it is then written to a new file, and the contents of that file are sent.  Eek,  Surely you need some content in the array...

     

     

    (Some comments in general.

    • Use "Camel case" for variable names, e.g buffer, newStart, newFileName, etc.  Then its simple to tell quickly whether an identifier is for a class/method/property or for a variable.  See http://msdn.microsoft.com/en-us/library/ms229043.aspx
    • Don't use BinaryWriter -- well very rarely.  The Stream class and subclass are streams of bytes, so in your case fs.Write(buffer, 0, buffer.Length) is good.  BinaryWriter should only ever be used in partnership with another .NET program using BinaryReader -- it encodes some data types in unexpected ways that will confuse programs not using BinaryReader).

    And on ObexWebRequest with local content.  There's no need to write to a file just for ObexWebRequest to read from that file. See the example in the user guide.  e.g. like:

        ...
        using (Stream content = request.GetRequestStream()) {
           content.Write(buffer, 0, buffer.length);
        }
        ObexWebResponse response = (ObexWebResponse)request.GetResponse();
        ...

     )

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 02-03-2010 4:55 PM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    Thanks for answering and for your work !!!

     I use now the last version (InTheHand.Net.Personal 2.5.0.0 and Widcomm 2.5.0.0) and I now got this error {"Connection closed whilst reading an OBEX packet."} in InTheHand.Net.ObexWebRequest.GetResponse()

    Stack :

    à InTheHand.Net.ObexWebRequest.StreamReadBlockMust(Stream stream, Byte[ buffer, Int32 offset, Int32 size)
    à InTheHand.Net.ObexWebRequest.CheckResponse(ObexStatusCode& status, Boolean isConnectResponse)
    à InTheHand.Net.ObexWebRequest.DoPut()
    à InTheHand.Net.ObexWebRequest.GetResponse()
    à TestInTheHand.Form1.button1_Click(Object sender, EventArgs e)
    à System.Windows.Forms.Control.OnClick(EventArgs e)
    à System.Windows.Forms.Button.OnClick(EventArgs e)
    à System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
    à System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
    à Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
    à System.Windows.Forms.Application.Run(Form fm)
    à TestInTheHand.Program.Main()

    The message is "Operation failed." and the Status is System.Net.WebExceptionStatus.Success

    In Output, I got this trace :

    'TestInTheHand.exe' (Managed): Loaded 'C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL\mscorlib.dll'

    'TestInTheHand.exe' (Managed): Loaded 'd:\dvlp\wmobile\testinthehand\testinthehand\bin\debug\TestInTheHand.exe', Symbols loaded.

    'TestInTheHand.exe' (Managed): Loaded 'C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL\System.Windows.Forms.dll'

    'TestInTheHand.exe' (Managed): Loaded 'C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL\System.dll'

    'TestInTheHand.exe' (Managed): Loaded 'C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL\System.Drawing.dll'

    'TestInTheHand.exe' (Managed): Loaded 'c:\apps\32feet.net installer\assemblies\ce2\InTheHand.Net.Personal.dll'

    A first chance exception of type 'System.PlatformNotSupportedException' occurred in InTheHand.Net.Personal.dll

    A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

    The thread 0xa3d61f72 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    A first chance exception of type 'System.NotSupportedException' occurred in InTheHand.Net.Personal.dll

    The thread 0xe4670e12 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    The thread 0xe4670e12 has exited with code 0 (0x0).

    and with the 32feet.config :

    Échec d'assertion
    Exception creating factory 'InTheHand.Net.Bluetooth.SocketsBluetoothFactory, ex: System.PlatformNotSupportedException: Microsoft Bluetooth stack not supported (radio).
    à InTheHand.Net.Bluetooth.SocketsBluetoothFactory..ctor()
    à System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
    à System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[ parameters, CultureInfo culture)
    à System.Reflection.ConstructorInfo.Invoke(Object[ parameters)
    à System.Activator.CreateInstance(Type type, Boolean nonPublic)
    à InTheHand.Net.Bluetooth.Factory.BluetoothFactory.GetStacks_inLock()
    à InTheHand.Net.Bluetooth.Factory.BluetoothFactory.get_Factories()
    à InTheHand.Net.Sockets.BluetoothClient..ctor()
    à InTheHand.Net.ObexWebRequest.Connect()
    à InTheHand.Net.ObexWebRequest.GetResponse()
    à TestInTheHand.Form1.button1_Click(Object sender, EventArgs e)
    à System.Windows.Forms.Control.OnClick(EventArgs e)
    à System.Windows.Forms.Button.OnClick(EventArgs e)
    à System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
    à System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
    à Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
    à System.Windows.Forms.Application.Run(Form fm)
    à TestInTheHand.Program.Main()

    à DefaultTraceListener.AssertFailure(String File, Int32 Line, String Expr)
    à DefaultTraceListener.Fail(String message, String detailMessage)
    à DefaultTraceListener.Fail(String message)
    à TraceInternal.Fail(String message)
    à TraceInternal.Assert(Boolean condition, String message)
    à BluetoothFactory.GetStacks_inLock()
    à BluetoothFactory.get_Factories()
    à BluetoothClient..ctor()
    à ObexWebRequest.Connect()
    à ObexWebRequest.GetResponse()
    à Form1.button1_Click(Object sender, EventArgs e)
    à Control.OnClick(EventArgs e)
    à Button.OnClick(EventArgs e)
    à ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
    à Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
    à EVL.EnterMainLoop(IntPtr hwnMain)
    à Application.Run(Form fm)
    à Program.Main()

     

    I got exactly the same error with ObjectPushApplication sample ! 

    Thanks !

  • 02-05-2010 6:23 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    So that's as I suspected.  The remote device is closing the connection whilst we're still expecting a response. :-(

    What's the remote device type and what content are you sending to it.  Can you try sending to the "Bluetooth File Transfer Wizard" application (StartMenu->Accessories->Communications).  Does it accept the PUT successfully?

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 02-06-2010 2:32 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

     Hello,

    The remote device type is a PC with a BELKIN USB dongle. I always can send files with "Bluetooth File Transfer Wizard", of any size.

     

    How yo know if my F900 accept the PUT ?

     Thanks

  • 02-06-2010 5:18 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    So you are sending from WM with ObexWebRequest.  The PC with Belkin Dongle is running Widcomm or MSFT?  What's the receiving app on the PC?  If Widcomm, the built-in service presumably?
    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 02-07-2010 5:21 PM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

     Exactly

    The Belkin dongle is running Widcomm (the about box says WIDCOMM Bluetooth Software 5.5.0.3200), the receive app is the built-in service, you're rigth.

     

  • 02-10-2010 6:29 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    I've sent 100,024 bytes from WM Widcomm ObexWebRequest to WinXP Widcomm built-in OBEX server. successfully.  So I wonder what's different in your case.  What file extension are you sending (I'm sending .txt (obexpush1.txt)) and what content (here just ASCII text)?

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 02-10-2010 8:11 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    In my code, I create a "false" text file :

    String CurrentDirectory = GetCurrentPath();
    String Filename = CurrentDirectory + @"\testfile_{0}.txt";

    I can send you my code, if you want.

     

  • 02-12-2010 11:32 AM In reply to

    Re: "IOError on socket." with 2.4.0.0 Beta

    Yes do that. My email address is my username here at yahoo.com. :-)
    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
Page 1 of 1 (10 items)
Copyright © 2001-2010 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.