示例#1
0
 /// <summary>
 /// 触发异常事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseOtherException(AsyncUDPState state, string descrip)
 {
     if (OtherException != null)
     {
         OtherException(this, new AsyncUDPEventArgs(descrip, state));
     }
 }
示例#2
0
 /// <summary>
 /// 触发数据发送完毕的事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseCompletedSend(AsyncUDPState state)
 {
     if (CompletedSend != null)
     {
         CompletedSend(this, new AsyncUDPEventArgs(state));
     }
 }
示例#3
0
 /// <summary>
 /// 触发网络错误事件
 /// </summary>
 /// <param name="state"></param>
 private void RaiseNetError(AsyncUDPState state)
 {
     if (NetError != null)
     {
         NetError(this, new AsyncUDPEventArgs(state));
     }
 }
示例#4
0
 /// <summary>
 /// 触发发送数据前的事件
 /// </summary>
 /// <param name="state"></param>
 private void RaisePrepareSend(AsyncUDPState state)
 {
     if (PrepareSend != null)
     {
         PrepareSend(this, new AsyncUDPEventArgs(state));
     }
 }
示例#5
0
 private void RaiseDataReceived(AsyncUDPState state)
 {
     if (DataReceived != null)
     {
         DataReceived(this, new AsyncUDPEventArgs(state));
     }
 }
示例#6
0
        /// <summary>
        /// 接收数据的方法
        /// </summary>
        /// <param name="ar"></param>
        private void ReceiveDataAsync(IAsyncResult ar)
        {
            IPEndPoint remote = null;

            byte[] buffer = null;
            try
            {
                buffer = _server.EndReceive(ar, ref remote);

                AsyncUDPState aus = new AsyncUDPState();
                aus.buffer = buffer;
                aus.remote = remote;

                //触发数据收到事件
                RaiseDataReceived(aus);
            }
            catch (Exception ex)
            {
                //TODO 处理异常
                RaiseOtherException(new AsyncUDPState(), ex.ToString());
            }
            finally
            {
                if (IsRunning && _server != null)
                {
                    _server.BeginReceive(ReceiveDataAsync, null);
                }
            }
        }
示例#7
0
 /// <summary>
 /// 关闭一个与客户端之间的会话
 /// </summary>
 /// <param name="state">需要关闭的客户端会话对象</param>
 public void Close(AsyncUDPState state)
 {
     if (state != null)
     {
         //_clients.Remove(state);
         //_clientCount--;
         //TODO 触发关闭事件
     }
 }
示例#8
0
 private void RaiseOtherException(AsyncUDPState state)
 {
     RaiseOtherException(state, "");
 }
示例#9
0
 public AsyncUDPEventArgs(string msg, AsyncUDPState state)
 {
     this._msg   = msg;
     this._state = state;
     IsHandled   = false;
 }
示例#10
0
 public AsyncUDPEventArgs(AsyncUDPState state)
 {
     this._state = state;
     IsHandled   = false;
 }