Esempio n. 1
0
        /// <summary>
        /// Listens for incoming commands in a loop.  This should be the only thread which reads from the [stream].
        /// </summary>
        private void CommandLoop(TcpClient tcpClient, Stream stream)
        {
            #region Command Loop
            while (tcpClient.Connected)
            {
                Command command = (Command)ByteUtil.ReadNBytes(stream, 1)[0];
                switch (command)
                {
                case Command.HostStatus:
                {
                    int        hostStatusLength = ByteUtil.ReadInt32(stream);
                    HostStatus hostStatus       = new HostStatus(stream, hostStatusLength);

                    break;
                }

                case Command.KeepAlive:
                    Logger.Info("Received Command.KeepAlive");
                    break;

                case Command.WebSocketConnectionRequest:
                    Logger.Info("Received Command.WebSocketConnectionRequest");
                    string proxyKey = ByteUtil.ReadUtf8_16(stream);
                    string sourceIp = ByteUtil.ReadUtf8_16(stream);
                    ServiceWrapper.BeginOutgoingWebSocketConnection(proxyKey, sourceIp);
                    break;

                default:
                    lock (writeLock)
                    {
                        stream.WriteByte((byte)Command.Error_CommandCodeUnknown);
                    }
                    break;
                }
            }
            #endregion
        }