示例#1
0
 public virtual void Receive()
 {
     if (this.Running)
     {
         UdpServerState state = new UdpServerState(new IPEndPoint(this._endpoint.Address, this._endpoint.Port));
         this._socket.BeginReceiveFrom(state.Data, 0, state.Data.Length, SocketFlags.None, ref state.Endpoint, this.ReceiveHandler, state);
     }
 }
示例#2
0
        protected virtual void ReceiveHandler(IAsyncResult ar)
        {
            UdpServerState state = (UdpServerState)ar.AsyncState;
            int            recv  = this._socket.EndReceiveFrom(ar, ref state.Endpoint);

            if (recv > 0)
            {
                this._handler.Received(state.Data, state.Endpoint);
            }
            this.Receive();
        }