Esempio n. 1
0
        private void ReceiveCompleted(object sender, SocketAsyncEventArgs e)
        {
            if (e.BytesTransferred > 0 && e.SocketError == SocketError.Success)
            {
                var      session = new UdpSession(e.RemoteEndPoint, this);
                TMessage message = null;

                try
                {
                    message = this._protocol.Parse(new ArraySegment <byte>(e.Buffer, 0, e.BytesTransferred));
                }
                catch (Exception ex)
                {
                    SocketBase.Log.Trace.Error(ex.Message, ex);
                    this._service.OnError(session, ex);
                }

                if (message != null)
                {
                    this._service.OnReceived(session, message);
                }
            }

            //receive again
            this.BeginReceive(e);
        }
Esempio n. 2
0
 public virtual void OnError(UdpSession session, Exception ex)
 {
 }
Esempio n. 3
0
 public virtual void OnReceived(UdpSession session, TMessage message)
 {
 }