List<Socket> socketList = new List<Socket>();
for(int i; i<socketList.Count; i++)
{
socketList.remove(i);
}
public void recv(IAsyncResult ar) // 用来接收数据
{
//Socket
try
{
int re = client.EndReceive(ar);
client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(recv), client); // 异步接收数据
}
catch (Exception e) // 异常处理
{
MessageBox.Show(e.ToString());
//int num = user_listBox.Items.Count;
Socket sc = (Socket)ar.AsyncState; // 显示异常的 socket
string strip = ((IPEndPoint)(sc.RemoteEndPoint)).Address.ToString(); // 提取异常的 socket 的 IP
MessageBox.Show("删除失踪的客户端!!!");
if (user_listBox.Items.Contains(strip))
{
user_listBox.Items.Remove(strip); // 删除 user_listBox 中的 异常 IP
MessageBox.Show("!!!!!!!!!!!!!!!!!!");
}
for (int i = 0; i < socketList.Count; i++)
{
socketList.Remove(sc); //删除异常的 socket
}
}
}
|