コード例 #1
0
        public void WriteBytes(byte[] v)
        {
            int len = GFWEncoding.SwapInt32(v.Length);

            this.writer.Write(len);
            this.writer.Write(v);
        }
コード例 #2
0
        public void WriteString(string v)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(v);
            ushort len   = GFWEncoding.SwapUInt16((ushort)bytes.Length);

            this.writer.Write(len);
            this.writer.Write(bytes);
        }
コード例 #3
0
        private void SendData()
        {
            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            while (this.mConnectState)
            {
                try
                {
                    if (this.mSendBuffers.Count == 0)
                    {
                        Thread.Sleep(1);
                        continue;
                    }
                    ByteBuffer buffer = null;
                    lock (this.mSendBuffers)
                    {
                        buffer = this.mSendBuffers.Dequeue();
                    }
                    if (buffer != null)
                    {
                        if (this.mSock != null && this.mSock.Connected)
                        {
                            byte[] message = buffer.ToBytes();
                            ms.SetLength(0L);
                            ms.Position = 0L;
                            ushort msglen = GFWEncoding.SwapUInt16((ushort)(message.Length + 4));
                            writer.Write(msglen);
                            ushort flag = GFWEncoding.SwapUInt16(1000);
                            writer.Write(flag);
                            writer.Write(message);
                            writer.Flush();
                            this.mSock.Send(ms.ToArray());
                        }
                        else
                        {
                            this.mConnectState = false;
                        }
                        buffer.Close();
                        buffer = null;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogWarning("Socket SendData Error:" + ex.Message);
                }
                Thread.Sleep(1);
            }
        }
コード例 #4
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);
 }
コード例 #5
0
 public void WriteUlong(ulong v)
 {
     v = GFWEncoding.SwapUInt64(v);
     this.writer.Write(v);
 }
コード例 #6
0
 public void WriteLong(long v)
 {
     v = GFWEncoding.SwapInt64(v);
     this.writer.Write(v);
 }
コード例 #7
0
 public void WriteInt(int v)
 {
     v = GFWEncoding.SwapInt32(v);
     writer.Write(v);
 }
コード例 #8
0
 public void WriteUint(uint v)
 {
     v = GFWEncoding.SwapUInt32(v);
     this.writer.Write(v);
 }
コード例 #9
0
 public void WriteShort(short v)
 {
     v = GFWEncoding.SwapInt16(v);
     writer.Write(v);
 }
コード例 #10
0
 public void WriteUshort(ushort v)
 {
     v = GFWEncoding.SwapUInt16(v);
     writer.Write(v);
 }
コード例 #11
0
 public ulong ReadUlong()
 {
     return(GFWEncoding.SwapUInt64(this.reader.ReadUInt64()));
 }
コード例 #12
0
 public long ReadLong()
 {
     return(GFWEncoding.SwapInt64(this.reader.ReadInt64()));
 }
コード例 #13
0
 public uint ReadUint()
 {
     return(GFWEncoding.SwapUInt32(this.reader.ReadUInt32()));
 }
コード例 #14
0
 public int ReadInt()
 {
     return(GFWEncoding.SwapInt32(this.reader.ReadInt32()));
 }
コード例 #15
0
 public ushort ReadUshort()
 {
     return(GFWEncoding.SwapUInt16(this.reader.ReadUInt16()));
 }
コード例 #16
0
 public short ReadShort()
 {
     return(GFWEncoding.SwapInt16(this.reader.ReadInt16()));
 }