public bool SendMessage(Message message)
        {
            User    receiver = new User();
            UserDAL userDAL  = new UserDAL();

            receiver      = userDAL.GetUserByUserId(message.Receiverid);
            message.State = receiver.State;
            if (receiver.State == 1)
            {
                //发送消息到服务端
                IPAddress ip           = IPAddress.Parse(IP.Ipaddress);
                Socket    clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                String    text         = receiver.Id + "###" + message.Content + "###" + message.Sendtype.ToString() + "###" + message.Userid;
                //设定服务器IP地址
                try
                {
                    clientSocket.Connect(new IPEndPoint(ip, IP.Port)); //配置服务器IP与端口
                }
                catch
                {
                    message.State = 0;
                    return(false);
                }
                clientSocket.Send(Encoding.UTF8.GetBytes(text));
            }
            MessageDAL messageDAL = new MessageDAL();

            messageDAL.AddMessage(message);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新增聊天信息记录
        /// </summary>
        /// <param name="message">聊天信息</param>
        /// <returns></returns>
        public bool AddMessage(MessageInfo message)
        {
            int affectRows = _messageDal.AddMessage(message);

            return(affectRows > 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增聊天信息记录
        /// </summary>
        /// <param name="message">聊天信息</param>
        /// <returns></returns>
        public bool AddMessage(MessageInfo message)
        {
            int AffectRows = messageDAL.AddMessage(message);

            return(AffectRows > 0);
        }