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); }
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); } }
public void WriteUshort(ushort v) { v = GFWEncoding.SwapUInt16(v); writer.Write(v); }
public ushort ReadUshort() { return(GFWEncoding.SwapUInt16(this.reader.ReadUInt16())); }