コード例 #1
0
        /// <summary>
        /// Handle the protocol and send to client by conn.
        /// </summary>
        /// <param name="conn">Conn.</param>
        /// <param name="protoBase">Proto base.</param>
        public void Send(Conn conn, ProtocolBase protoBase)
        {
            byte[] strBytes  = protoBase.Encode();
            byte[] lenBytes  = BitConverter.GetBytes(strBytes.Length);
            byte[] sendBytes = lenBytes.Concat(strBytes).ToArray();

            try {
                conn.socket.Send(sendBytes);
            } catch (Exception ex) {
                Console.WriteLine("[ServNet.Send] Send bytes fail. " + ex.Message);
            }
        }
コード例 #2
0
ファイル: ServNet.cs プロジェクト: fzzx20080212/Ser
 public void Send(Conn conn, ProtocolBase protocol)
 {
     byte[] bytes    = protocol.Encode();
     byte[] length   = BitConverter.GetBytes(bytes.Length);
     byte[] sendbuff = length.Concat(bytes).ToArray();
     try
     {
         conn.socket.BeginSend(sendbuff, 0, sendbuff.Length, SocketFlags.None, null, null);
     }
     catch (Exception e)
     {
         Console.WriteLine("[发送信息]" + conn.GetAdress() + ":" + e.Message);
     }
 }