An operation was attempted on something that is not a socket

Topics: Bluetooth - Stonestreet
Apr 17, 2012 at 7:39 PM

Right after I connect to a MC9090G, I get this exception:  Chat2Device.exe BluetopiaSocketException.   An operation was attempted on something that is not a socket.

It was working great but now it won't connect, I don't remember making any changes in the settings.  This happens with chat2device and also with my app.   I tested with 2 MC9090G and they both throw the exception.   It connects with no problem to a MC3190Z.

What is causing it?

Thanks in advance!

Developer
Apr 18, 2012 at 5:49 PM

Can you show me the full exception including both the full message and the stack trace.  That will indicate where and what is occuring.  NotSocket is a code used as a catch-all when something unexpected occurs.

Apr 23, 2012 at 6:59 PM

Here is the full exception:

InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaSocketException was unhandled  Message="An operation was attempted on something that is not a socket (Bluetopia: RFCOMM_ADDING_SERVER_INFORMATION (-68))."  ErrorCode=10038  NativeErrorCode=10038  BluetopiaError="RFCOMM_ADDING_SERVER_INFORMATION"  BluetopiaErrorCode=-68  StackTrace:       at InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaUtils.Throw(BluetopiaError ret, String descr)       at InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaUtils.CheckAndThrow(BluetopiaError ret, String descr)       at InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaRfcommStream.DoOpenServer(Int32 scn)       at InTheHand.Net.Bluetooth.Factory.CommonRfcommStream.BeginAccept(BluetoothEndPoint bep, String serviceName, AsyncCallback asyncCallback, Object state)       at InTheHand.Net.Bluetooth.Factory.CommonBluetoothListener._StartOneNewListenerPort_inLock()       at InTheHand.Net.Bluetooth.Factory.CommonBluetoothListener.StartEnoughNewListenerPort_inLock()       at InTheHand.Net.Bluetooth.Factory.CommonBluetoothListener.PortAcceptCallback(IAsyncResult ar)       at InTheHand.Net.AsyncResultNoResult.CallbackRunner(Object state)       at System.Threading.ThreadPool.WorkItem.doWork(Object o)       at System.Threading.Timer.ring()

 

Also, I've noticed that the Listener initialization fails.  It doesn't throw an exception but after the initialization I look into the "listener" and get this:

?listener
{InTheHand.Net.Sockets.BluetoothListener}
    Authenticate: False
    Encrypt: False
    LocalEndPoint: Property evaluation failed.
    Server: {"This stack does not use sockets."}
    ServiceClass: {"The method or operation is not implemented."}
    ServiceName: Property evaluation failed.
    ServiceRecord: Property evaluation failed.

 

Also, sometimes when I exit the app, it gives me the error:

 

InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaSocketException was unhandled  Message="An invalid argument was supplied (Bluetopia: INVALID_BLUETOOTH_STACK_ID (-2))."  ErrorCode=10022  NativeErrorCode=10022  BluetopiaError="INVALID_BLUETOOTH_STACK_ID"  BluetopiaErrorCode=-2  StackTrace:       at InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaUtils.Throw(BluetopiaError ret, String descr)       at InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaUtils.CheckAndThrow(BluetopiaError ret, String descr)       at InTheHand.Net.Bluetooth.StonestreetOne.BluetopiaRfcommStream.DoOpenServer(Int32 scn)       at InTheHand.Net.Bluetooth.Factory.CommonRfcommStream.BeginAccept(BluetoothEndPoint bep, String serviceName, AsyncCallback asyncCallback, Object state)       at InTheHand.Net.Bluetooth.Factory.CommonBluetoothListener._StartOneNewListenerPort_inLock()       at InTheHand.Net.Bluetooth.Factory.CommonBluetoothListener.StartEnoughNewListenerPort_inLock()       at InTheHand.Net.Bluetooth.Factory.CommonBluetoothListener.PortAcceptCallback(IAsyncResult ar)       at InTheHand.Net.AsyncResultNoResult.SetAsCompleted(Exception exception, AsyncResultCompletion completion)       at InTheHand.Net.AsyncResultNoResult.SetAsCompleted(Exception exception, Boolean completedSynchronously)       at InTheHand.Net.Bluetooth.Factory.CommonRfcommStream.Dispose(Boolean disposing)       at InTheHand.Net.Bluetooth.Factory.CommonRfcommStream.Finalize()

Developer
Apr 24, 2012 at 12:57 PM

Ok I should have thought of this intially.  As I mention at http://32feet.codeplex.com/wikipage?title=Stonestreet%20One%20Bluetopia

"The current BluetoothListener support is preliminary. It isn't clear from the API how to support multiple connections to the same port number, or even whether multiple concurrent connections to the same port number are supportable."

So what happens is that the BtLsnr in Chat2Device accepts the connection and then tries to listen again and thus an error occurs. The company who funded the porting to Bluetopia did not use server-side so I created the listener support as an extra and didn't need to find some workaround for that issue.

Do you need service-side support there or is this just for testing?

Apr 24, 2012 at 4:04 PM
Edited Apr 24, 2012 at 4:04 PM

Yes, the way the application should work is - There is a "Master Device", which is a Juniper Mesa with MS Bluetooth stack that will collect data from the "Client Devices", which are MC9090Gs running Bluetopia stack.  

Initially, I was trying to connect from the Master to the Client but since I couldn't get the listener to work on the client, I reversed it.

So now I can get everything to work by having a "Transmit" button on the client that connects to the master device and then the data gets transferred.

However we would like to have this initiated by the master and not require the client to press a button or anything.   All I need now is a way of "pinging" the MC9090G from the Mesa so to tell it to connect but I haven't found anything that works so far.  Suggestions would be very welcome! :)

Developer
Apr 26, 2012 at 8:42 AM

Nothing really comes to mind for your case except for having a listener.

However it should be possible to make BtLsnr work on SSO Bluetopia.

  • The simplest thing would be for the library to catch that error internally so that there's no direct crash (the listener would have to be restarted after the first accept though).
  • There's also the possibility to some gymnastics to only actually start the new listening object when the first closes.  That would be a fair amount of work.
  • A third might be to try and get an answer from SSO what the expected behaviour should be -- is it possible to accept or even wait-to-accept a new connection after one has been accepted, or is it one-at-a-time only?

I'll have a look at the first sometime soon.

Apr 26, 2012 at 2:50 PM

That would be great!   I tried to catch the exception in the application but it was the type ThreadAbortException and it cascades out of the catch.   Then I tried to use Thread.ResetAbort but it is not supported in the compact framework.

Developer
Apr 26, 2012 at 7:30 PM

I've done number 1. See bug 32626 "BluetoothListener: Error on new port causes unhandleable exception"

"[...]  In the Bluetopia case previously the 'one port at a time' error was unhandled and occurred on a background thread and therefore killed the application. Now it is caught and returned to the next Accept. Even better the first Accept successfully returns back to the caller. So BluetoothListener is now usable to that extent: one connection can be accepted. After that it needs to be discarded and a new server created. [...]"

('ve also fixed another wee thing I found in testing -- mostly unrelated to this.  Bug 32628 "BluetoothListener: stop new Accept calls from being made when not Started")

A good days work.

All donations etc gratefully received. :-)

Apr 26, 2012 at 8:57 PM
Edited Apr 26, 2012 at 8:57 PM

Thanks Alan, that's pretty awesome, i'll ask my boss about the donation :)

Are you planning to post a new install for download?   I was able to build following the instructions but when I run MakeInstaller I get several errors.

Developer
Apr 27, 2012 at 12:29 PM

Yup, a new release is on the to-do list.  It's straightforward except from the annoying native Widcomm DLLs, but I'll try to get it done soon.

You don't need to run the MakeInstaller.cmd just copy the DLL from bin\Release  For a release I use the VS installer thingy.  I just use MakeInstaller.cmd for testing.