Пример #1
0
        public bool Send(Message msg)
        {
            if (m_NetworkStream != null)
            {
                // Prepare the message
                m_Writer.BaseStream.Position = 0;
                msg.Serialise(m_Writer);
                int size = (int)m_Writer.BaseStream.Position;

                // Send the message
                try
                {
                    m_NetworkStream.WriteByte((byte)msg.Type);
                    m_NetworkStream.WriteByte((byte)size);
                    if (size > 0)
                    {
                        m_NetworkStream.Write(m_Buffer, 0, size);
                    }

                    return true;
                }
                catch (SocketException e)
                {
                    Debug.WriteLine("[NetworkWriter.Send] " + e.Message);
                }
                catch (IOException e)
                {
                    Debug.WriteLine("[NetworkWriter.Send] " + e.Message);
                }
            }

            return false;
        }
Пример #2
0
 public bool ReadMessage(Message msg)
 {
     bool success = false;
     if (m_PendingType == msg.Type)
     {
         success = msg.Serialise(m_Reader);
         m_PendingType = MessageType.Invalid;
     }
     return success;
 }