Пример #1
0
        private void OnReceived(IAsyncResult result)
        {
            try
            {
                if (_client == null)
                {
                    var client = (UdpClient)result.AsyncState;
                    client.EndReceive(result, ref _endPoint);
                    return;
                }

                var ea = new IncomingUdpMessageEventArgs();
                ea.Message = Encoding.Default.GetString(_client.EndReceive(result, ref _endPoint));
                OnIncomingMessage(ea);

                if (ea.Message.StartsWith("$SR"))
                {
                    var args = new SearchResultEventArgs {
                        Message = SRMessage.Parse(ea.Message)
                    };
                    OnSearchResult(args);
                }
            }
            catch (Exception x)
            {
            }
            finally
            {
                if (_client != null)
                {
                    _client.BeginReceive(OnReceived, null);
                }
            }
        }
Пример #2
0
        private void OnIncomingMessage(IncomingUdpMessageEventArgs e)
        {
            var handler = IncomingMessage;

            if (handler != null)
            {
                handler(this, e);
            }
        }