示例#1
0
 protected override void ParseChunk(Chunk chunk)
 {
     base.ParseChunk(chunk);
     if (_sendToken)
     {
         _sendToken = false;
         sendToken();
     }
 }
示例#2
0
        public virtual void Update()
        {
            if (CanReceiveData())
            {
                var data = ReceivedData();
                var memory = new MemoryStream(data);
                var reader = new EndianBinaryReader(EndianBitConverter.Big, memory);

                while (memory.Position < memory.Length)
                {
                    switch (CurrentState)
                    {
                        case ClientStates.Handshake_WaitForS0:
                            {
                                reader.ReadByte();
                                CurrentState = ClientStates.Handshake_WaitForS1;
                            }
                            break;
                            case ClientStates.Handshake_WaitForS1:
                            {
                                var s1Chunk = reader.ReadBytes(Globals.Handshake_Length);
                                SendData(Handshake.GenerateC2(s1Chunk));
                                CurrentState = ClientStates.Handshake_WaitForS2;
                            }
                            break;
                            case ClientStates.Handshake_WaitForS2:
                            {
                                var s2Chunk = reader.ReadBytes(Globals.Handshake_Length);
                                CurrentState = ClientStates.Handshake_Done;
                            }
                            break;
                            case ClientStates.Handshake_Done:
                            {
                                var chunk = new Chunk();
                                chunk.Load(memory);
                                ParseChunk(chunk);
                            }
                            break;
                    }
                }
            }
        }
示例#3
0
 public void SendMessage(Chunk chunk)
 {
     SendData(chunk.ToBytes());
 }
示例#4
0
        protected virtual void ParseChunk(Chunk chunk)
        {
            //TODO: Add automatic responses to window acknowledgements

            if (chunk.MHeader.MessageType == 5 || chunk.MHeader.MessageType == 3) //This are acknowledgements
            {
                var ack = new WindowAcknowledgement(-1);
                ack.ParseChunkData(chunk);
                SendMessage(new WindowAcknowledgement(ack.WindowSize));
            }
        }
示例#5
0
 public void ParseChunkData(Chunk chunk)
 {
     var dataMemory = new MemoryStream(chunk.Data);
     ParseChunkData(dataMemory);
 }