Esempio n. 1
0
        private void DataArrival(byte[] Data, IPAddress ip, int port)
        {
            ClassMsg msg = new ClassSerializers().DeSerializeBinary((new MemoryStream(Data))) as ClassMsg;
            switch (msg.sendKind)
            {
                case SendKind.SendCommand:
                    {
                        switch (msg.msgCommand)
                        {
                            case MsgCommand.GetFriendList:
                                ShowFriendList(msg);
                                break;
                        }

                        break;
                    }

            }
        }
Esempio n. 2
0
        /// <summary>
        /// 登录函数
        /// </summary>
        private void login_()
        {
            string hostname = string.Empty;
            string serID = string.Empty;

            User.user.UserName = Username_textbox.Text;
            User.user.PassWord1 = Password_textbox.Text;
            //string[] sMessage = { "", "" };
            //bSuccess = User.Login(User.user.UserName, User.user.PassWord1, ref sMessage);
            //if (bSuccess)
            //{
            #region 发送登录消息
            //向服务器发送登录消息
            hostname = Dns.GetHostName();
            //IPAddress[] ip = Dns.GetHostAddresses(hostname);
            LoginMsg loginmsg = new LoginMsg();
            //RegisterMsg registmsg = new RegisterMsg();
            ClassMsg msg = new ClassMsg();
            //registmsg.UserName = Username_textbox.Text;
            //registmsg.PassWord = Password_textbox.Text;
            loginmsg.UserName = Username_textbox.Text;
            loginmsg.PassWord = Password_textbox.Text;
            byte[] logindata = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
            msg.sendKind = SendKind.SendCommand;
            msg.msgCommand = MsgCommand.Logining;
            msg.Data = logindata;
            serID = "192.168.1.187";                 //服务器IP
            udpSocket1.Send(IPAddress.Parse(serID), 11001, new ClassSerializers().SerializeBinary(msg).ToArray());
            #endregion

            //}
            //else
            //{
            //    if (!string.IsNullOrEmpty(sMessage[0]))
            //        MessageBox.Show(sMessage[0]);
            //    else
            //        MessageBox.Show(sMessage[1]);
            //}
        }
Esempio n. 3
0
        private void DataArrival(byte[] Data, IPAddress ip, int port)
        {
            ClassMsg msg = new ClassSerializers().DeSerializeBinary((new MemoryStream(Data))) as ClassMsg;
            switch (msg.sendKind)
            {
                case SendKind.SendCommand:
                    {
                        switch (msg.msgCommand)
                        {
                            case MsgCommand.Logining:
                                MessageBox.Show("登录失败,用户名密码错误!");
                                break;
                            case MsgCommand.Logined:
                                User.user.UserID = Convert.ToInt16(msg.SID);
                                D_login();
                                udpSocket1.Active = false;
                                break;
                        }

                        break;
                    }

            }
        }
Esempio n. 4
0
 private void frmChat_Load(object sender, EventArgs e)
 {
     UserBLL udb = new UserBLL();
     //聊天对象信息表
     DataTable dt = new DataTable();
     //用户好友列表
     DataTable dt1 = new DataTable();
     //用户信息表
     DataTable dt2 = new DataTable();
     dt = udb.Userinfo(ChatUserID);
     dt1 = udb.GetFriendShipInfo(udb.user.UserID.ToString(), ChatUserID.ToString());
     dt2 = udb.Userinfo(udb.user.UserID);
     Text = "与" + dt1.Rows[0]["AlternateName"] + "聊天中";
     FriendName.Text = dt1.Rows[0]["AlternateName"].ToString();
     UserName.Text = dt2.Rows[0]["UserNickName"].ToString();
     if (string.IsNullOrEmpty(dt.Rows[0]["HeadPicture"].ToString()))
     {
         FriendHead.ImageLocation = s + "\\search_teacher.jpg";
     }
     else
     {
         FriendHead.ImageLocation = dt.Rows[0]["HeadPicture"].ToString();
     }
     if (string.IsNullOrEmpty(dt2.Rows[0]["HeadPicture"].ToString()))
     {
         UserHead.ImageLocation = s + "\\search_teacher.jpg";
     }
     else
     {
         UserHead.ImageLocation = dt2.Rows[0]["HeadPicture"].ToString();
     }
     hostname = Dns.GetHostName();
     IPAddress[] ip = Dns.GetHostAddresses(hostname);
     RegisterMsg registmsg = new RegisterMsg();
     ClassMsg msg = new ClassMsg();
     registmsg.UserName = "******";
     registmsg.PassWord = "******";
     byte[] registdata = new ClassSerializers().SerializeBinary(registmsg).ToArray();
     msg.sendKind = SendKind.SendCommand;
     msg.msgCommand = MsgCommand.Registering;
     msg.Data = registdata;
     serID = "192.168.1.187";
     udpSocket1.Send(IPAddress.Parse(serID), 11000, new ClassSerializers().SerializeBinary(msg).ToArray());
 }
Esempio n. 5
0
 private void main_Load(object sender, EventArgs e)
 {
     UserBLL udb = new UserBLL();
     ClassMsg msg = new ClassMsg();
     LoginMsg loginmsg = new LoginMsg();
     msg.sendKind = SendKind.SendCommand;
     msg.msgCommand = MsgCommand.GetFriendList;
     msg.SID = udb.user.UserID.ToString();
     loginmsg.UserName = udb.user.UserName;
     byte[] loginbyte = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
     msg.Data = loginbyte;
     udpSocket1.Send(IPAddress.Parse(serIP),10001,new ClassSerializers().SerializeBinary(msg).ToArray());
     ////用户信息表
     //DataTable dt = new DataTable();
     ////好友表
     //DataTable dt1 = new DataTable();
     ////分组信息表
     //DataTable dt2 = new DataTable();
     ////好友详细信息表
     //DataTable dt3 = new DataTable();
     //dt = udb.Userinfo(udb.user.UserID);
     //Name_skinLable.Text = udb.user.UserNickName;
     //PersonalMessage.Text = udb.user.UserPersonalMessage;
     //chatListBox1.Items.Clear();
     //dt2 = udb.DB.GetData(string.Format("select * from friendgroup where userID={0}", udb.user.UserID));
     //if (string.IsNullOrEmpty(dt.Rows[0]["HeadPicture"].ToString()))
     //{
     //    headpicture.ImageLocation = s + "\\search_teacher.jpg";
     //}
     //else
     //{
     //    headpicture.ImageLocation = dt.Rows[0]["HeadPicture"].ToString();
     //}
     //for (int i = 0; i < dt2.Rows.Count; i++)
     //{
     //    ChatListItem chatlist1 = new ChatListItem();
     //    chatlist1.Bounds = new System.Drawing.Rectangle(0, 53, 363, 25);
     //    chatlist1.IsTwinkleHide = false;
     //    chatlist1.OwnerChatListBox = this.chatListBox1;
     //    chatlist1.Text = dt2.Rows[i]["GrouName"].ToString();
     //    chatlist1.TwinkleSubItemNumber = 0;
     //    chatListBox1.Items.AddRange(new ChatListItem[] { chatlist1 });
     //    dt1 = udb.GetFriendList(udb.user.UserName, dt2.Rows[i]["GrouID"].ToString());
     //    for (int l = 0; l < dt1.Rows.Count; l++)
     //    {
     //        dt3 = udb.DB.GetData(string.Format("select * from user where UserID={0}", dt1.Rows[l]["Use_UserID"]));
     //        ChatListSubItem chatListSubItem1 = new ChatListSubItem();
     //        chatListSubItem1.Bounds = new System.Drawing.Rectangle(0, 0, 0, 0);
     //        chatListSubItem1.DisplayName = dt1.Rows[l]["Alternatename"].ToString();
     //        chatListSubItem1.HeadImage = null;
     //        chatListSubItem1.HeadRect = new System.Drawing.Rectangle(0, 0, 0, 0);
     //        chatListSubItem1.ID = Convert.ToInt32(dt1.Rows[l]["Use_UserID"]);
     //        chatListSubItem1.IpAddress = null;
     //        chatListSubItem1.IsTwinkle = false;
     //        chatListSubItem1.IsTwinkleHide = false;
     //        chatListSubItem1.NicName = dt3.Rows[0]["UserNickName"].ToString();
     //        chatListSubItem1.OwnerListItem = chatlist1;
     //        chatListSubItem1.PersonalMsg = dt3.Rows[0]["UserPersonalMessage"].ToString();
     //        chatListSubItem1.Status = ChatListSubItem.UserStatus.Online;
     //        chatListSubItem1.Tag = null;
     //        chatListSubItem1.TcpPort = 0;
     //        chatListSubItem1.UpdPort = 0;
     //        chatlist1.SubItems.AddRange(new ChatListSubItem[] {chatListSubItem1});
     //    }
     //}
 }
Esempio n. 6
0
 /// <summary>
 /// 当有数据到达后的处理进程
 /// </summary>
 /// <param name="Data"></param>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 private void DataArrival(byte[] Data, IPAddress ip, int port)
 {
     try
     {
         ClassMsg msg = new ClassSerializers().DeSerializeBinary((new MemoryStream(Data))) as ClassMsg;
         switch (msg.sendKind)
         {
             case SendKind.SendCommand:  //命令
                 {
                     switch (msg.msgCommand)
                     {
                         case MsgCommand.Registering://注册用户
                             RegisterUser(msg, ip, port);
                             break;
                         case MsgCommand.Logining://登录用户
                             UserLogin(msg, ip, port, 1);
                             break;
                         case MsgCommand.UserList://用户列表
                             SendUserList(msg, ip, port);
                             break;
                         case MsgCommand.GetFriendList://获取好友列表
                             SendFriendList(msg, ip, port);
                             break;
                         case MsgCommand.SendToOne://发送消息给单用户
                             SendUserMsg(msg, ip, port);
                             break;
                         case MsgCommand.Close://下线
                             UpdateUserState(msg, ip, port);
                             break;
                     }
                     break;
                 }
             case SendKind.SendMsg://消息
                 {
                     switch (msg.msgCommand)
                     {
                         case MsgCommand.SendToOne://发送消息给单用户
                             SendUserMsg(msg, ip, port);
                             break;
                     }
                     break;
                 }
             case SendKind.SendFile://文件
                 {
                     break;
                 }
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Esempio n. 7
0
 private void SendMsgToOne(IPAddress ip, int port, ClassMsg msg)
 {
     try
     {
         MemoryStream stream = new ClassSerializers().SerializeBinary(msg);
         UDPSocket udp = new UDPSocket();
         udp.Send(ip, port, stream.ToArray());
     }
     catch
     { }
 }
Esempio n. 8
0
 /// <summary>
 /// 发送信息给所有用户
 /// </summary>
 /// <param name="msg"></param>
 private void SendMsgToAll(ClassMsg msg)
 {
     try
     {
         foreach (ListViewItem item in this.LV_SysUser.Items)
         {
             IPAddress ip = IPAddress.Parse(item.SubItems[1].Text);
             int port = Convert.ToInt32(item.SubItems[2].Text);
             MemoryStream stream = new ClassSerializers().SerializeBinary(msg);
             UDPSocket udp = new UDPSocket();
             udp.Send(ip, port, stream.ToArray());
         }
     }
     catch
     { }
 }