Ejemplo n.º 1
0
 /// <summary>
 /// 触发异常事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseOtherException(TCPClientHandle handle, string descrip)
 {
     if (OtherException != null)
     {
         OtherException(this, new TCPEventArgs(descrip, handle));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 触发数据发送事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseCompletedSend(TCPClientHandle handle)
 {
     if (CompletedSend != null)
     {
         CompletedSend(this, new TCPEventArgs(handle));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 触发网络错误事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseNetError(TCPClientHandle handle)
 {
     if (NetError != null)
     {
         NetError(this, new TCPEventArgs(handle));
     }
 }
Ejemplo n.º 4
0
 private void RaiseDataReceived(TCPClientHandle handle)
 {
     if (DataReceived != null)
     {
         DataReceived(this, new TCPEventArgs(handle));
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 触发客户端连接事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseClientConnected(TCPClientHandle handle)
 {
     if (ClientConnected != null)
     {
         ClientConnected(this, new TCPEventArgs(handle));
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 关闭一个与客户端之间的会话
 /// </summary>
 /// <param name="handle">需要关闭的客户端会话对象</param>
 public void Close(TCPClientHandle handle)
 {
     if (handle != null)
     {
         _clients.Remove(handle);
         handle.Dispose();
         _clientCount--;
         //TODO 触发关闭事件
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 开始进行监听
        /// </summary>
        private void Accept()
        {
            TCPClientHandle handle;

            while (IsRunning)
            {
                TcpClient client = _listener.AcceptTcpClient();
                if (_clientCount >= _maxClient)
                {
                    //TODO 触发事件
                }
                else
                {
                    handle = new TCPClientHandle(client);
                    _clientCount++;
                    _clients.Add(handle);

                    //TODO 创建一个处理客户端的线程并启动
                    //使用线程池来操作
                    new Thread(new ThreadStart(handle.RecevieData)).Start();
                }
            }
        }
Ejemplo n.º 8
0
 private void RaiseOtherException(TCPClientHandle handle)
 {
     RaiseOtherException(handle, "");
 }
Ejemplo n.º 9
0
 public TCPEventArgs(string msg, TCPClientHandle handle)
 {
     this._msg    = msg;
     this._handle = handle;
     IsHandled    = false;
 }
Ejemplo n.º 10
0
 public TCPEventArgs(TCPClientHandle handle)
 {
     this._handle = handle;
     IsHandled    = false;
 }