GetServerConnection() public method

public GetServerConnection ( ) : NetworkConnection
return NetworkConnection
        private void Connect()
        {
            ClientConfig config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);

            // Only set the server info is we are connecting on awake
            if (connectOnAwake)
            {
                config.SetServerAddress(ServerAddress);
                config.SetServerPort(ServerPort);
            }

            sharingMgr = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = sharingMgr.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);

            SyncStateListener = new SyncStateListener();
            sharingMgr.RegisterSyncListener(SyncStateListener);

            Root = new SyncRoot(sharingMgr.GetRootSyncObject());

            this.SessionsTracker     = new ServerSessionsTracker(sharingMgr.GetSessionManager());
            this.SessionUsersTracker = new SessionUsersTracker(this.SessionsTracker);

            using (XString userName = new XString(DefaultUserName))
            {
                sharingMgr.SetUserName(userName);
            }
        }
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (this.discoveryClient != null)
            {
                discoveryClient.RemoveListener(this.discoveryClientAdapter);
                discoveryClient.Dispose();
                discoveryClient = null;

                if (discoveryClientAdapter != null)
                {
                    discoveryClientAdapter.Dispose();
                    discoveryClientAdapter = null;
                }
            }

            if (sharingMgr != null)
            {
                // Force a disconnection so that we can stop and start Unity without connections hanging around
                sharingMgr.GetPairedConnection().Disconnect();
                sharingMgr.GetServerConnection().Disconnect();
            }

            // Release the Sharing resources
            if (this.SessionUsersTracker != null)
            {
                this.SessionUsersTracker.Dispose();
                this.SessionUsersTracker = null;
            }

            if (this.SessionsTracker != null)
            {
                this.SessionsTracker.Dispose();
                this.SessionsTracker = null;
            }

            if (networkConnection != null)
            {
                networkConnection.RemoveListener((byte)MessageID.StatusOnly, networkConnectionAdapter);
                networkConnection.Dispose();
                networkConnection = null;

                if (networkConnectionAdapter != null)
                {
                    networkConnectionAdapter.Dispose();
                    networkConnectionAdapter = null;
                }
            }

            if (sharingMgr != null)
            {
                sharingMgr.Dispose();
                sharingMgr = null;
            }

            // Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects
            GC.Collect();
        }
示例#3
0
        private void Connect()
        {
            ClientConfig config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);
            config.SetServerAddress(ServerAddress);
            config.SetServerPort(ServerPort);
            config.SetProfilerEnabled(false);

            sharingMgr = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = sharingMgr.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);
        }