日期:2014-05-17 浏览次数:20808 次
/// <summary>
/// 收包处理委托
/// </summary>
/// <param name="buffer"></param>
/// <param name="socket"></param>
/// <returns></returns>
public delegate bool ReceivePacketHandle(byte[] buffer, Socket socket);
/// <summary>
/// 客户端接受委托
/// </summary>
public delegate void ClientChangedHandle(object state);
public abstract class PacketTransferBase
{
/// <summary>
/// Socket列表
/// </summary>
public SortedList<int, Socket> SocketClientList { get; private set; }
/// <summary>
/// 客户端接收事件
/// </summary>
public event ClientChangedHandle OnClientAccepted;
/// <summary>
/// 客户端关闭事件
/// </summary>
public event ClientChangedHandle OnClientClosed;
/// <summary>
/// 收包处理事件
/// </summary>
public event ReceivePacketHandle OnReceivePacket;
public PacketTransferBase()
{
SocketClientList = new SortedList<int, Socket>();
}
/// <summary>
/// 保存客户端,以待每次接收后进行判断等功能
/// </summary>
/// <param name="socketClient"></param>
protected void AddClient(Socket socketClient)
{
lock (SocketClientList)
&