public void StartServer()
        {
            if (isStarted)
            {
                return;
            }

            startedMutex.WaitOne();

            isStarted = true;

            discovery.DoStart();

            PairingState.Value = ServerPairingState.None;

            server = new NetworkServerSimple();

            server.RegisterHandler(MsgType.Connect, OnConnect);

            server.RegisterHandler(MsgType.Disconnect, OnDisconnect);

            server.RegisterHandler(PairingRequestMessage.GetCustomMsgType(), OnPairingRequest);

            server.Listen(serverPort);

            startedMutex.ReleaseMutex();
        }
        public void SendPairingRequest(bool pairing = true)
        {
            PairingRequestMessage pairingRequestMsg = new PairingRequestMessage();

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            // Use project path as ID to enable debugging from the same device
            pairingRequestMsg.deviceId = Application.dataPath;// SystemInfo.deviceUniqueIdentifier;
#else
            pairingRequestMsg.deviceId = SystemInfo.deviceUniqueIdentifier;
#endif

            string deviceName = SystemInfo.deviceModel;

            if (Utils.CurrentDeviceType == DeviceType.Tablet)
            {
                pairingRequestMsg.deviceType = DeviceType.Tablet;
            }
            else if (Utils.CurrentDeviceType == DeviceType.Headset)
            {
                pairingRequestMsg.deviceType = DeviceType.Headset;
            }

            client.Send(
                (short)(pairing ? CustomMsgType.PairingRequest : CustomMsgType.UnpairingRequest),
                pairingRequestMsg);
        }
        private void OnPairingRequest(NetworkMessage netMsg)
        {
            PairingRequestMessage msg = netMsg.ReadMessage <PairingRequestMessage>();

            if (msg.deviceType == DeviceType.Tablet && TabletId.IsNullOrEmpty())
            {
                TabletId           = msg.deviceId;
                tabletConnection   = netMsg.conn;
                PairingState.Value = ServerPairingState.Tablet;
                Pairing();
            }
            else if (msg.deviceType == DeviceType.Headset && HeadsetId.IsNullOrEmpty())
            {
                HeadsetId          = msg.deviceId;
                headsetConnection  = netMsg.conn;
                PairingState.Value = ServerPairingState.Headset;
                Pairing();
            }
            else
            {
                PairingState.Value = ServerPairingState.None;
                SendTargetPairingResult(netMsg.conn, false);
            }
        }