server destructor

asked 2014-06-01 14:19:19 -0700

riko642 gravatar image

updated 2014-06-01 14:22:22 -0700

I'm using the samples/unity/server code. What do I need to include in the server destructor in order to fully cancel the server and be able to start it again from the same instance of application even with the same name?

I'm using the following code now:

            sJoinComplete = false;

it works only for the 1st and 2nd start&cancel. It doesn't start the server properly when I try to start it for the 3rd time. This is the log of the 3rd attempt to start after 2 previous starts and cancels:

Server Interface Created.

Server BusListener Registered.

Server BusAttachment started.

Server ListenerRegistered: busAttachment=AllJoynUnity.AllJoyn+BusAttachment


Is my destructor for client correct?:

            sJoinCalled = false;
            sJoinComplete = false;
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-02 12:19:08 -0700

georgen gravatar image

The proper way to do what you are talking about is as follows:

// This tell the Routing Node that you want to stop using the BusAttachment
// Stop() is a non-blocking call and will return instantly.  That is fine typically if you don't 
// plan on starting up the server again. If you want to start up the server again you should
// also call Join this will tell the code to wait till the call to Stop() has completed
// Because of the C# garbage collector there are parts of the BusAttachment that may still be 
// Around calling the Dispose method will verify all Native parts of the code are freed without 
// waiting for the garbage collector to collect the native resources.

Side note creating and connecting a BusAttachment is a very processor and resource intense action. It is not something you want to setup and tear down regularly. In most situations its best to create it once and Just reuse the created BusAttachment.

edit flag offensive delete publish link more


Thank you for your answer, but it still fails to start it for the 3rd time. I want to make an app where the user will be able to start or connect to a server, but it should allow the user to disconnect or cancel server and all the fundamental "hosting" functionality

riko642 ( 2014-06-07 08:48:31 -0700 )edit

Or should I use only single BusAttachment within the same app rather then create(destroy) them when the server(client) is started(stopped)?

riko642 ( 2014-06-07 10:21:06 -0700 )edit

That is what I would suggest. Create a single BusAttachment an leave it running. If you have really simple reproduction step for the problem you are seeing you could submit a bug.( jira.allseenalliance.org )

georgen ( 2014-06-17 09:41:48 -0700 )edit

@riko642 If the response from @georgen solves the issue can you mark it as correct?

bspencer ( 2014-10-01 16:24:10 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-06-01 14:19:19 -0700

Seen: 100 times

Last updated: Jun 02 '14