private void removeAllSelectedFromAllList() { if (this.All_Send_Addr_listView.SelectedItems.Count > 0) { this.All_Send_Addr_listView.BeginUpdate(); this.Need_Send_Addr_listView.BeginUpdate(); foreach (ListViewItem item in this.All_Send_Addr_listView.SelectedItems) { IpAddr ip = new IpAddr(); ip.IpAddrs = item.Text; ip.Port = item.SubItems[1].Text; this.sendList.Add(ip); this.All_Send_Addr_listView.Items.Remove(item); ListViewItem nitem = new ListViewItem(); nitem.Text = ip.IpAddrs; nitem.SubItems.Add(ip.Port); this.Need_Send_Addr_listView.Items.Add(nitem); } this.All_Send_Addr_listView.EndUpdate(); this.Need_Send_Addr_listView.EndUpdate(); } }
private void button2_Click(object sender, EventArgs e) { if (this.send_ipBox2.Text.Equals("")) { MessageBox.Show("请输入发送IP地址!"); return; } if (this.send_port_box.Text.Equals("")) { MessageBox.Show("请输入发送端口号!"); return; } IpAddr sendip = new IpAddr(); sendip.IpAddrs = this.send_ipBox2.Text; sendip.Port = this.send_port_box.Text; this.send_ipAddrList.Add(sendip); this.addToListView(sendip); this.send_ipBox2.clearText(); this.send_port_box.Text = ""; }
public Form1() { InitializeComponent(); rec_ipAddress = new IpAddr(); send_ipAddrList = new List <IpAddr>(); sktUtil = new SocketUtil(); connecionstate = false; }
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); }
private void addToListView(IpAddr sendip) { this.send_listview.BeginUpdate(); ListViewItem item = new ListViewItem(); item.Text = sendip.IpAddrs; item.SubItems.Add(sendip.Port); this.send_listview.Items.Add(item); this.send_listview.EndUpdate(); }
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(); } }
private void addToAllList() { if (this.Need_Send_Addr_listView.SelectedItems.Count > 0) { ListViewItem item = this.Need_Send_Addr_listView.SelectedItems[0]; IpAddr ip = new IpAddr(); ip.IpAddrs = item.Text; ip.Port = item.SubItems[1].Text; this.Need_Send_Addr_listView.BeginUpdate(); this.Need_Send_Addr_listView.Items.Remove(item); this.Need_Send_Addr_listView.EndUpdate(); this.All_Send_Addr_listView.BeginUpdate(); ListViewItem nitem = new ListViewItem(); nitem.Text = ip.IpAddrs; nitem.SubItems.Add(ip.Port); this.All_Send_Addr_listView.Items.Add(nitem); this.All_Send_Addr_listView.EndUpdate(); this.sendList.Remove(ip); } }