public override void SendEmptyMessage(int id)
        {
            OutData od = outpool.Get();

            CopyBytes(0, od.data, 0);
            CopyBytes((UInt16)id, od.data, 2);
            od.total = 4;
            outqueue.Enqueue(od);

            if (status == SocketStatus.Ok)
            {
                lock (this)
                {
                    if (sending == 0)
                    {
                        BeginSend();
                    }
                }
            }
        }
 private void BeginSend()
 {
     Interlocked.Exchange(ref sending, 1);
     try
     {
         if (outqueue.Count > 0)
         {
             OutData od = outqueue.Peek() as OutData;
             socket.BeginSend(od.data, 0, od.total, SocketFlags.None, EndSend, socket);
         }
         else
         {
             Interlocked.Exchange(ref sending, 0);
         }
     }
     catch (Exception ex)
     {
         Interlocked.Exchange(ref sending, 0);
         Debug.LogException(ex);
     }
 }
        public override void SendProtoMessage(int id, Stream stream)
        {
            stream.Seek(0, SeekOrigin.Begin);
            OutData od  = outpool.Get();
            int     len = stream.Read(od.data, 4, (int)stream.Length);

            CopyBytes((UInt16)len, od.data, 0);
            CopyBytes((UInt16)id, od.data, 2);
            od.total = len + 4;
            outqueue.Enqueue(od);

            if (status == SocketStatus.Ok)
            {
                lock (this)
                {
                    if (sending == 0)
                    {
                        BeginSend();
                    }
                }
            }
        }