Esempio n. 1
0
 private void OnReceive(byte[] bytes, int length)
 {
     this.readStream.Seek(0L, SeekOrigin.End);
     this.readStream.Write(bytes, 0, length);
     this.readStream.Seek(0L, SeekOrigin.Begin);
     while (this.readStream.Length - this.readStream.Position > 4L)
     {
         uint messageLen = this.reader.ReadUInt32();
         uint len        = GFWEncoding.SwapUInt32(messageLen);
         len -= 4u;
         if (!(this.readStream.Length - this.readStream.Position >= (long)((ulong)len)))
         {
             this.readStream.Position = this.readStream.Position - 4L;
             break;
         }
         ByteBuffer buffer = new ByteBuffer(this.reader.ReadBytes((int)len));
         DispatchMessage(Protocal.Message, buffer);
     }
     byte[] leftover = this.reader.ReadBytes((int)(this.readStream.Length - this.readStream.Position));
     this.readStream.SetLength(0L);
     this.readStream.Write(leftover, 0, leftover.Length);
 }
Esempio n. 2
0
 public void WriteUint(uint v)
 {
     v = GFWEncoding.SwapUInt32(v);
     this.writer.Write(v);
 }
Esempio n. 3
0
 public uint ReadUint()
 {
     return(GFWEncoding.SwapUInt32(this.reader.ReadUInt32()));
 }