コード例 #1
0
    public void ReceiveCallback_RemoteSurface(IAsyncResult ar)
    {
        Byte[] receiveBytes = _udpClient_RemoteSurface.EndReceive(ar, ref _anyIP_RemoteSurface);
        string result       = System.Text.Encoding.UTF8.GetString(receiveBytes);

        string[] trackermessage = result.Split(MessageSeparators.L0);
        result = trackermessage[0] + MessageSeparators.L0 + trackermessage[1];
        Sensor[] sensors = _retrieveSensors(trackermessage[2]);
        foreach (Sensor s in sensors)
        {
            Debug.Log("_REMOTE_SENSOR______________________________________ " + s.id);
        }


        if (SurfaceMessage.isMessage(result))
        {
            SurfaceRectangle s = new SurfaceRectangle(result);
            Debug.Log("SURFACE_________________________________________ " + s.ToString());
            s.sensors = sensors;
            if (_main != null)
            {
                _main.setRemoteSurface(s);
            }
            if (_calibration != null)
            {
                _calibration.setRemoteSurface(s);
            }
            _udpClient_RemoteSurface.Close();
        }
        else
        {
            _udpClient_RemoteSurface.BeginReceive(new AsyncCallback(this.ReceiveCallback_RemoteSurface), null);
        }
    }
コード例 #2
0
 /// <inheritdoc />
 public void sendMessage(string handleRecepient, SurfaceMessage srfMsg)
 {
     lock (this)
     {
         skype.SendMessage(handleRecepient, srfMsg.text);
         Logger.log(TLogLevel.logEverything, "Info: Sent SrfMsg " + srfMsg.type + ": " + srfMsg.payload);
     }
 }
コード例 #3
0
    private void _request(string trackerPort, string receivePort)
    {
        UdpClient  udp            = new UdpClient();
        IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, int.Parse(trackerPort));
        string     message        = SurfaceMessage.createRequestMessage(int.Parse(receivePort));

        byte[] data = Encoding.UTF8.GetBytes(message);
        udp.Send(data, data.Length, remoteEndPoint);
    }
コード例 #4
0
    public void ReceiveCallback_RemoteSurface(IAsyncResult ar)
    {
        Byte[] receiveBytes = _udpClient_RemoteSurface.EndReceive(ar, ref _anyIP_RemoteSurface);
        string result       = System.Text.Encoding.UTF8.GetString(receiveBytes);

        _log.WriteLine("[SurfaceRequestListener] Remote Surface Received");

        if (SurfaceMessage.isMessage(result))
        {
            _main.setRemoteSurface(new SurfaceRectangle(result));
            _udpClient_RemoteSurface.Close();
        }
        else
        {
            _udpClient_RemoteSurface.BeginReceive(new AsyncCallback(this.ReceiveCallback_RemoteSurface), null);
        }
    }
コード例 #5
0
    public void ReceiveCallback_LocalSurface(IAsyncResult ar)
    {
        Byte[] receiveBytes = _udpClient_LocalSurface.EndReceive(ar, ref _anyIP_LocalSurface);
        string result       = System.Text.Encoding.UTF8.GetString(receiveBytes);

        if (SurfaceMessage.isMessage(result))
        {
            _surface = new SurfaceRectangle(result);

            Debug.Log(_surface.ToString());

            _udpClient_LocalSurface.Close();
        }
        else
        {
            _udpClient_LocalSurface.BeginReceive(new AsyncCallback(this.ReceiveCallback_LocalSurface), null);
        }
    }
コード例 #6
0
    public void ReceiveCallback_RemoteSurface(IAsyncResult ar)
    {
        Byte[] receiveBytes = _udpClient_RemoteSurface.EndReceive(ar, ref _anyIP_RemoteSurface);
        string result       = System.Text.Encoding.UTF8.GetString(receiveBytes);

        string[] trackermessage = result.Split(MessageSeparators.L0);
        result = trackermessage[0] + MessageSeparators.L0 + trackermessage[1];
        Sensor[] sensors = _retrieveSensors(trackermessage[2]);
        if (SurfaceMessage.isMessage(result))
        {
            SurfaceRectangle s = new SurfaceRectangle(result);
            s.sensors = sensors;
            _main.setRemoteSurface(s);
            _udpClient_RemoteSurface.Close();
        }
        else
        {
            _udpClient_RemoteSurface.BeginReceive(new AsyncCallback(this.ReceiveCallback_RemoteSurface), null);
        }
    }
コード例 #7
0
    void Awake()
    {
        Debug.Log("Hello Tracker");
        _clouds           = new Dictionary <string, PointCloudSimple> ();
        _cloudGameObjects = new Dictionary <string, GameObject>();
        _loadConfig();



        UdpClient udp     = new UdpClient();
        string    message = AvatarMessage.createRequestMessage(1, TrackerProperties.Instance.listenPort);

        byte[]     data           = Encoding.UTF8.GetBytes(message);
        IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, TrackerProperties.Instance.trackerPort);

        Debug.Log("Sent request to port" + TrackerProperties.Instance.trackerPort + " with content " + message);
        udp.Send(data, data.Length, remoteEndPoint);

        message = SurfaceMessage.createRequestMessage(TrackerProperties.Instance.listenPort);
        data    = Encoding.UTF8.GetBytes(message);
        Debug.Log("Sent request to port" + TrackerProperties.Instance.trackerPort + " with content " + message);
        udp.Send(data, data.Length, remoteEndPoint);
    }
コード例 #8
0
 /// <inheritdoc />
 public void sendMessage(SurfaceMessage srfMsg)
 {
     commOverSkype.sendMessage(handleParticipant, srfMsg);
 }
コード例 #9
0
 public UndeployedMessage(SurfaceMessage surfaceMessage, String fromHandle)
 {
     this._fromHandle = fromHandle;
     this._surfaceMessage = surfaceMessage;
 }
コード例 #10
0
        private void onSkypeMessageStatus(ChatMessage message, TChatMessageStatus status)
        {
            Logger.log(TLogLevel.logEverything, "Info: " + status + "Id: " + message.Id + " " + message.Body);
            //we're only processing received messages
            //note: when the chat messages window is open cmsReceived is skipped and the first state is cmsRead
            switch (status)
            {
                case TChatMessageStatus.cmsRead:
                case TChatMessageStatus.cmsReceived:
                    break;

                default:
                    return;
            }

            lock(this)
            {
                message.Seen = true;
                Stack<SurfaceMessage> srfMsgsToProcess = new Stack<SurfaceMessage>();

                //check if this is the first message of the current session
                if (firstMessages.ContainsKey(message.FromHandle) == false)
                {
                    //we got the first message in this session, just save its id
                    firstMessages[message.FromHandle] = message.Id;
                }

                //check all message till the first one of this session if they were already processed

                /*
                 * Note: skype.Messages[message.FromHandle] is necesarry, since message.Chat.Messages
                 * is never updated after once accessed.
                 */
                Logger.log(TLogLevel.logEverything, "Info: Walking through messages:");
                foreach (ChatMessage m in skype.Messages[message.FromHandle])
                {
                    Logger.log(TLogLevel.logEverything, "\tId: " + m.Id );

                    if (m.Id < firstMessages[message.FromHandle])
                    {
                        break;
                    }

                    if (knownMessages.Contains(m.Id) == false)
                    {
                        //we got a new message
                        knownMessages.Add(m.Id);
                        SurfaceMessage srfMsg = new SurfaceMessage(m.Body);
                        if (srfMsg.valid == true)
                        {
                            Logger.log(TLogLevel.logEverything, "Info: Got Surface Message: " + srfMsg.payload);
                            srfMsgsToProcess.Push(srfMsg);
                        }
                    }

                    if (m.Id == firstMessages[message.FromHandle])
                    {
                        break;
                    }
                }

                foreach (SurfaceMessage srfMsg in srfMsgsToProcess)
                {
                    //call specific message handler
                    if (this._surfaceSpecificMessageHandlers.ContainsKey(message.FromHandle))
                    {
                        this._surfaceSpecificMessageHandlers[message.FromHandle](srfMsg);
                    }
                    else
                    {
                        //if no specific message handler is present, save the message for later deployment
                        Logger.log(TLogLevel.logDebug, "Info: No listener registered for SrfMsg: " + srfMsg.payload);

                        //lock access to undeployedMessages
                        lock (undeployedMessages)
                        {
                            if (undeployedMessages.Count >= maxUndeployedMessages)
                            {
                                undeployedMessages.Dequeue();
                            }
                            undeployedMessages.Enqueue(new UndeployedMessage(srfMsg, message.FromHandle));
                        }
                    }

                    //finally call generic message handlers
                    foreach (DSurfaceMessageHandler srfMsgHandler in this._surfaceMessageHandlers)
                    {
                        srfMsgHandler(message.FromHandle, srfMsg);
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// This should be called whenever a Surface message is received from the corresponding participant.
        /// </summary>
        /// <param name="surfaceMessage">The message that was received.</param>
        private void surfaceMessageReceived(SurfaceMessage surfaceMessage)
        {
            Logger.log(TLogLevel.logEverything, "Info: Received Surface message: " + surfaceMessage.type);
            // We don't want any race-condition here, aight?
            lock(this)
            {
                //reset deploy flags
                this._deployBtm2Btm = false;
                this._deployKrypt2Krypt = false;

                bool authentic = false;

                switch (surfaceMessage.type)
                {
                    case TSurfaceMessage.Syn:
                        //todo: authentication
                        synReceived(authentic);
                        break;

                    case TSurfaceMessage.Ack:
                        ackReceived(authentic);
                        break;

                    case TSurfaceMessage.Nack:
                        //todo: authentication
                        nackReceived(authentic);
                        break;

                    case TSurfaceMessage.Bottom2Bottom:

                        String btmMsg;
                        //decrypt
                        try
                        {
                            btmMsg = kryptonite.decryptMessage(surfaceMessage.payload);
                            authentic = true;
                        }
                        catch (ExceptionCryptoFailed)
                        {
                            Logger.log(TLogLevel.logDebug, "Error: Decrypting of Bottom message failed.");
                            break;
                        }

                        btm2btmReceived(authentic);

                        //check if deploy has been set by the underlying state-machine
                        if (this._deployBtm2Btm == true)
                        {
                            //deploy
                            bottom.messageReceived(btmMsg);
                        }
                        break;

                    case TSurfaceMessage.Kryptonite2Kryptonite:
                        krypt2kryptReceived(true);

                        //check if deploy has been set by the underlying state-machine
                        if (this._deployKrypt2Krypt == true)
                        {
                            //deploy

                            bool oldSecure = kryptonite.isSecure;
                            try
                            {
                                kryptonite.messageReceived(surfaceMessage.payload);
                            }
                            catch (ExceptionCryptoFailed)
                            {
                                Logger.log(TLogLevel.logDebug, "Error: Deploying of Kryptonite message failed.");
                            }

                            //check if the security status of this session changed
                            if (oldSecure != kryptonite.isSecure)
                            {
                                securityStatusChanged();
                            }
                        }
                        break;

                    case TSurfaceMessage.Closing:
                        closingReceived(authentic);
                        break;

                    case TSurfaceMessage.Unknown:
                        unknownReceived(authentic);
                        break;

                    default:
                        //drop
                        break;
                }
            }
        }
コード例 #12
0
 /// <summary>
 /// Sends a Kryptonite message encapsulated into a Surface message.
 /// </summary>
 /// <param name="rawMessage">The message to be send.</param>
 private void sendKryptoniteMessage(String rawMessage)
 {
     SurfaceMessage srfMsg = new SurfaceMessage(TSurfaceMessage.Kryptonite2Kryptonite, rawMessage);
     surfaceComm.sendMessage(srfMsg);
 }
コード例 #13
0
        /// <summary>
        /// Sends a Bottom message encapsulated into a Surface message.
        /// </summary>
        /// <param name="rawMessage">The message to be send.</param>
        private void sendBottomMessage(String rawMessage)
        {
            String encryptedMessage;
            try
            {
                encryptedMessage = kryptonite.encryptMessage(rawMessage);
            }
            catch
            {
                Logger.log(TLogLevel.logUser, "Error: Encryption of Bottom protocol message failed.");
                return;
            }

            SurfaceMessage srfMsg = new SurfaceMessage(TSurfaceMessage.Bottom2Bottom, encryptedMessage);
            surfaceComm.sendMessage(srfMsg);
        }
コード例 #14
0
ファイル: Core.cs プロジェクト: flxflx/watchasayin
 private void onSurfaceMessage(string senderHandle, SurfaceMessage srfMsg)
 {
     Logger.log(TLogLevel.logEverything,"Got srfMsg: " + srfMsg.payload);
 }