Esempio n. 1
0
 internal override string GetCommandLogString()
 {
     return($"{Arg.Handle} {Arg.Datalen} ({BytesConvert.ToHexString(Arg.Data)})");
 }
Esempio n. 2
0
 internal override string GetCommandLogString()
 {
     return($"{Arg.Handle} {Arg.Ipaddr} {Arg.Port} {(char)Arg.Sec} {Arg.Datalen} ({BytesConvert.ToHexString(Arg.Data)})");
 }
Esempio n. 3
0
 public static string HexString(byte[] bytes) => BytesConvert.ToHexString(bytes);
Esempio n. 4
0
        public LANClient(ILogger <LANClient> logger)
        {
            var selfAddresses = NetworkInterface.GetAllNetworkInterfaces().SelectMany(ni => ni.GetIPProperties().UnicastAddresses.Select(ua => ua.Address.ToString()));

            _logger = logger;
            try
            {
                receiveUdpClient = new UdpClient(DefaultUdpPort)
                {
                    EnableBroadcast = true
                };
            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex, "Exception");
                throw;
            }
            Task.Run(async() =>
            {
                try
                {
                    while (true)
                    {
                        var receivedResults = await receiveUdpClient.ReceiveAsync();
                        if (selfAddresses.Contains(receivedResults.RemoteEndPoint.Address.ToString()))
                        {
                            //ブロードキャストを自分で受信(無視)
                            continue;
                        }
                        _logger.LogDebug($"UDP受信:{receivedResults.RemoteEndPoint.Address.ToString()} {BytesConvert.ToHexString(receivedResults.Buffer)}");
                        OnEventReceived?.Invoke(this, (receivedResults.RemoteEndPoint.Address.ToString(), receivedResults.Buffer));
                    }
                }
                catch (System.ObjectDisposedException)
                {
                    //握りつぶす
                }
                catch (Exception ex)
                {
                    _logger.LogDebug(ex, "Exception");
                }
            });
        }