c# Socket服务器端怎么来判断客户端出现断开问题,并刷新列表呢?急,在线等!!!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO ;
using System.Runtime.InteropServices;
namespace ChatServer
{
public class ClientSeverForm : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.GroupBox grpSocket;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbSocketPort;
private System.Windows.Forms.TextBox tbSocketClientsNum;
private System.Windows.Forms.RichTextBox rtbSocketMsg;
private System.Windows.Forms.Button btnSocketStart;
private System.Windows.Forms.Button btnSocketStop;
private System.Windows.Forms.ListBox lbSocketClients;
//clients数组保存当前在线用户的Client对象
internal static Hashtable clients=new Hashtable();
//该服务器默认的监听的端口号
private TcpListener listener;
//服务器可以支持的最多的客户端的连接数
static int MAX_NUM=100;
private TextBox txtLogin;
//开始服务的标志
internal static bool SocketServiceFlag = false;
/// <summary>
/// 有新消息来时闪烁任务栏并且保持聊天记录内容滚动到最底端,QQ就是这么玩滴~
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DllImport("user32.dll")]
public static extern bool FlashWindow(IntPtr hWnd, bool bInvert);
private void rtbSocketMsg_TextChanged(object sender, EventArgs e)
{
rtbSocketMsg.ScrollToCaret();
if (this.WindowState == FormWindowState.Minimized)
{
FlashWindow(this.Handle, true);
}
}
public ClientSeverForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
}