Пример #1
0
 /// <summary>
 /// 触发网络错误事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseNetError(TCPClientHandle handle)
 {
     if (NetError != null)
     {
         NetError(this, new TCPEventArgs(handle));
     }
 }
Пример #2
0
 /// <summary>
 /// 触发异常事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseOtherException(TCPClientHandle handle, string descrip)
 {
     if (OtherException != null)
     {
         OtherException(this, new TCPEventArgs(descrip, handle));
     }
 }
Пример #3
0
 /// <summary>
 /// 触发数据发送事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseCompletedSend(TCPClientHandle handle)
 {
     if (CompletedSend != null)
     {
         CompletedSend(this, new TCPEventArgs(handle));
     }
 }
Пример #4
0
 private void RaiseDataReceived(TCPClientHandle handle)
 {
     if (DataReceived != null)
     {
         DataReceived(this, new TCPEventArgs(handle));
     }
 }
Пример #5
0
 /// <summary>
 /// 触发客户端连接事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseClientConnected(TCPClientHandle handle)
 {
     if (ClientConnected != null)
     {
         ClientConnected(this, new TCPEventArgs(handle));
     }
 }
Пример #6
0
 /// <summary>
 /// 关闭一个与客户端之间的会话
 /// </summary>
 /// <param name="handle">需要关闭的客户端会话对象</param>
 public void Close(TCPClientHandle handle)
 {
     if (handle != null)
     {
         _clients.Remove(handle);
         handle.Dispose();
         _clientCount--;
         //TODO 触发关闭事件
     }
 }
Пример #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);
                    RaiseClientConnected(handle);
                    //TODO 创建一个处理客户端的线程并启动
                    //使用线程池来操作
                    new Thread(new ThreadStart(handle.RecevieData)).Start();
                }
            }
        }
Пример #8
0
 public TCPEventArgs(string msg, TCPClientHandle handle)
 {
     this._msg    = msg;
     this._handle = handle;
     IsHandled    = false;
 }
Пример #9
0
 public TCPEventArgs(TCPClientHandle handle)
 {
     this._handle = handle;
     IsHandled    = false;
 }
Пример #10
0
 private void RaiseOtherException(TCPClientHandle handle)
 {
     RaiseOtherException(handle, "");
 }
Пример #11
0
 /// <summary>
 /// 发送函数
 /// </summary>
 public void Send(byte[] data, TCPClientHandle client)
 {
     //TODO
     client.SendData(data);
 }