Exemplo n.º 1
0
 public void addUcf(Friend f)
 {
     UcFriend ucf = new UcFriend();
     ucf.Frm=this;
     ucf.CurFriend = f;
     ucf.Top = this.pnFriendList.Controls.Count*ucf.Height;
     this.pnFriendList.Controls.Add(ucf);
 }
Exemplo n.º 2
0
        public void listen()
        {
            UdpClient uc = new UdpClient(9527);
            while (true)
            {
                IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 0);

                byte[] bmsg = uc.Receive(ref ipep);
                string msg = Encoding.Default.GetString(bmsg);

                string[] datas = msg.Split('|');
                string msgHead=datas[0];
                switch(msgHead)
                {
                    case "LOGIN":
                        if (datas.Length != 4)
                    {
                        continue;
                    }

                    if(getMyIP().ToString()==ipep.Address.ToString())
                    {
                        continue;
                    }

                    Friend friend = new Friend();

                    int curIndex = Convert.ToInt32(datas[2]);
                    if (curIndex < 0 || curIndex >= _frm.ilHeadImages.Images.Count)
                    {
                        curIndex = 0;
                    }
                    friend.HeadImageIndex = curIndex;
                    friend.NickName = datas[1];
                    friend.Shuoshuo = datas[3];
                    friend.IP = ipep.Address;
                    object[] pars = new object[1];
                    pars[0] = friend;
                    _frm.Invoke(new delAddFriend(_frm.addUcf), pars);

                    //回发,告诉对方我也在  ALSOON|头像|昵称|说说
                    break;
                    case "ALSOON":
                        break;
                    default:
                        break;
                }

                //if (datas[0] == "LOGIN")
                //{

                //}

            }
        }
Exemplo n.º 3
0
        private void listen()
        {
            UdpClient uc = new UdpClient(9527);
            while (true)
            {
                IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 0);

                byte[] bmsg = uc.Receive(ref ipep);
                string msg = Encoding.Default.GetString(bmsg);
               // MessageBox.Show(msg);
                string[] datas = msg.Split('|');
                if (datas.Length != 4)
                {
                    continue;
                }
                if(datas[0] =="LOGIN")
                {
                   // MessageBox.Show(datas[1]);
                    Friend friend = new Friend();

                    int curIndex = Convert.ToInt32(datas[2]);
                    if(curIndex<0 || curIndex >= this.ilHeadImages.Images.Count)
                    {
                        curIndex = 0;
                    }
                    friend.HeadImageIndex =curIndex;
                    friend.NickName=datas[1];
                    friend.Shuoshuo = datas[3];

                    object[] pars=new object[1];
                    pars[0] = friend;
                    this.Invoke(new delAddFriend(this.addUcf),pars);
                }
            }
        }