예제 #1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            t = new Thread(new ThreadStart(Helper)); //实例化线程
            t.Start();                               //启动线程
            IpAddr ipaddr = (IpAddr)e.Argument;

            receive_socket = sktUtil.getConnection(ipaddr.IpAddrs, ipaddr.Port);
        }
예제 #2
0
        private void button8_Click(object sender, EventArgs e)
        {
            if (this.send_result_listView.Items.Count == 0)
            {
                MessageBox.Show("发送地址为空!");
                return;
            }

            foreach (ListViewItem item in this.send_result_listView.Items)
            {
                this.send_result_listView.BeginUpdate();
                IpAddr ip = new IpAddr();
                ip.IpAddrs = item.Text;
                ip.Port    = item.SubItems[1].Text;
                SocketUtil sktutil      = new SocketUtil();
                Socket     clientSocket = sktutil.getConnection(ip.IpAddrs, ip.Port);
                if (clientSocket != null)
                {
                    bool success = sktutil.sendMessage(clientSocket, this.message);
                    if (success)
                    {
                        string response = sktutil.receiveMessage(clientSocket);
                        //MessageBox.Show(response);

                        item.SubItems.Add("回应:" + response);
                    }
                    else
                    {
                        item.SubItems.Add("失败");
                    }

                    sktutil.disConnection(clientSocket);
                }
                else
                {
                    item.SubItems.Add("无法连接");
                }
                this.send_result_listView.EndUpdate();
            }
        }