コード例 #1
0
ファイル: NetAsynSend.cs プロジェクト: mengtest/fs
 /// <summary>
 /// 发送消息是发送前压包,再发送
 /// </summary>
 private void SendMessage()
 {
     for (int i = 0; i < m_msgList.Count; i++)
     {
         MessageCache cache = m_msgList[i];
         Conn         conn  = cache.conn;
         if (conn != null && conn.socket != null && conn.socket.Connected)
         {
             NetMessage msg = cache.msg;
             m_stream.Reset();
             msg.ToByte(ref m_stream);
             try
             {
                 if (msg.msgID != 200)
                 {
                     Console.WriteLine(m_serverType + ":发送消息:" + (eNetMessageID)msg.msgID);
                 }
                 conn.socket.BeginSend(m_stream.GetBuffer(), 0, msg.msgMaxLen, SocketFlags.None, null, conn);
             }
             catch (Exception e)
             {
                 Console.WriteLine(m_serverType + ":[错误]发送消息异常,id:" + (eNetMessageID)msg.msgID + " " + conn.GetAdress() + " : " + e.Message);
             }
         }
     }
     m_msgList.Clear();
 }