예제 #1
0
파일: Program.cs 프로젝트: smeckl/KBLA-Sec
        static CollectionAgentMessage ReadMessage(SslStream sslStream)
        {
            // Read the  message sent by the server.
            // The end of the message is signaled using the
            // "<EOF>" marker.
            byte[]        buffer      = new byte[2048];
            StringBuilder messageData = new StringBuilder();
            int           bytes       = -1;

            do
            {
                bytes = sslStream.Read(buffer, 0, buffer.Length);

                // Use Decoder class to convert from bytes to UTF8
                // in case a character spans two buffers.
                Decoder decoder = Encoding.UTF8.GetDecoder();
                char[]  chars   = new char[decoder.GetCharCount(buffer, 0, bytes)];
                decoder.GetChars(buffer, 0, bytes, chars, 0);
                messageData.Append(chars);

                // Check for EOF.
                if (messageData.ToString().IndexOf("<EOF>") != -1)
                {
                    break;
                }
            } while (bytes != 0);

            Console.WriteLine(messageData.ToString());

            String strJSON = messageData.ToString();

            // If there is a trailing <EOF> character, strip it so that JSON
            // deserialization will work correctly
            int index = (strJSON.IndexOf("<EOF>"));

            if (index != -1)
            {
                strJSON = strJSON.Substring(0, index);
            }

            ICommandMessageFactory factory = new CommandMessageFactory();

            GetRegistryKeyResponseMessage deserializedMsg =
                (GetRegistryKeyResponseMessage)factory.constructMessageFromJSON("GetRegistryKeyResponseMessage", strJSON);

            // Return the new object
            return(deserializedMsg);
        }
예제 #2
0
        internal RtmpServerOptions()
        {
            var userControlMessageFactory = new UserControlMessageFactory();
            var commandMessageFactory     = new CommandMessageFactory();

            RegisterMessage <AbortMessage>();
            RegisterMessage <AcknowledgementMessage>();
            RegisterMessage <SetChunkSizeMessage>();
            RegisterMessage <SetPeerBandwidthMessage>();
            RegisterMessage <WindowAcknowledgementSizeMessage>();
            RegisterMessage <DataMessage>((MessageHeader header, SerializationContext context, out int consumed) =>
            {
                consumed = 0;
                return(new DataMessage(header.MessageType == MessageType.Amf0Data ? AmfEncodingVersion.Amf0 : AmfEncodingVersion.Amf3));
            });
            RegisterMessage <VideoMessage>();
            RegisterMessage <AudioMessage>();
            RegisterMessage <UserControlMessage>(userControlMessageFactory.Provide);
            RegisterMessage <CommandMessage>(commandMessageFactory.Provide);
            _rpcService = new RpcService();
        }