Exemple #1
0
 public FormClient()
 {
     InitializeComponent();
     listBoxStatus.HorizontalScrollbar = true;
     setListBoxCallback            = new SetListBoxCallback(SetListBox);
     setRichTextBoxReceiveCallback = new SetRichTextBoxReceiveCallback(SetRichTextBoxReceive);
 }
Exemple #2
0
 private void Chat_Load(object sender, EventArgs e)
 {
     setRichTextBoxReceiveCallback = new SetRichTextBoxReceiveCallback(SetRichTextBoxReceive);
     AsyncCallback requestCallback = new AsyncCallback(RequestCallback);
 }
Exemple #3
0
        private void Form2_Load(object sender, EventArgs e)
        {
            setRichTextBoxReceiveCallback = new SetRichTextBoxReceiveCallback(SetRichTextBoxReceive);


            //setRichTextBoxReceiveCallback = new SetRichTextBoxReceiveCallback(SetRichTextBoxReceive);

            IPAddress[] ip = Dns.GetHostAddresses(Dns.GetHostName());
            Console.WriteLine(ip[1]);


            //使用IPv4,实现应用时要将Dns.GetHostName()改为服务器名

            client = new TcpClient(AddressFamily.InterNetwork);
            IPAddress serverIP = IPAddress.Parse("118.25.48.83");

            AsyncCallback requestCallback = new AsyncCallback(RequestCallback);

            allDone.Reset();

            //开始对远程主机的异步请求
            client.BeginConnect(serverIP, 8886, requestCallback, client);

            //阻塞线程直到BeginConnect完成,连接完成自动调用RequestCallback中的Set方法解除阻塞
            allDone.WaitOne();

            HttpHelper http   = new HttpHelper();
            HttpItem   item1  = new HttpItem();
            HttpResult result = new HttpResult();

            item1 = new HttpItem()
            {
                URL         = "http://localhost/api/login/friends",//URL     必需项
                UserAgent   = "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)",
                Method      = "post",
                Postdata    = "id=" + getstr,
                ContentType = "application/x-www-form-urlencoded; Charset=UTF-8",
                Accept      = "*/*",
            };
            result = http.GetHtml(item1);
            chatListBox1.Items.Clear();
            string html = result.Html;

            getstr = html;
            Console.WriteLine(html);
            JArray jar = JArray.Parse(html);


            ChatListItem item = new ChatListItem("好友列表 ");

            foreach (var jsonitem in jar)
            {
                JObject job = (JObject)jsonitem;
                string  id  = job["id"].ToString();
                Console.WriteLine(id);
                ChatListSubItem subItem = new ChatListSubItem(job["name"].ToString(), job["name"].ToString(), job["sign"].ToString());
                Console.WriteLine(job["F_friendID"]);
                string img = job["img"].ToString();
                //subItem.IpAddress = job["ip"].ToString();
                subItem.HeadImage = Image.FromStream(System.Net.WebRequest.Create(img).GetResponse().GetResponseStream());
                string state = job["flag"].ToString();
                if (state == "1")
                {
                    subItem.Status = (ChatListSubItem.UserStatus)(0);
                }
                else
                {
                    subItem.Status = (ChatListSubItem.UserStatus)(5);
                }



                item.SubItems.AddAccordingToStatus(subItem);
            }

            chatListBox1.Items.Add(item);
        }