0

server destructor

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

riko642 gravatar image

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

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:

~BasicServer()
        {
            sJoinComplete = false;
            msgBus.Stop();
            msgBus.UnregisterAllHandlers();
        }

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

SubQuestion

Is my destructor for client correct?:

~BasicClient()
        {
            sJoinCalled = false;
            sJoinComplete = false;
        }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

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

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
msgBus.Stop();  
// 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
msgBus.Join()
// 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.
msgBus.Dispose();

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

Comments

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 -0800 )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 -0800 )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 -0800 )edit

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

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

Question Tools

Follow
1 follower

Stats

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

Seen: 110 times

Last updated: Jun 02 '14