public UdpSendUtils CreateConnection(BattleRoyaleClientMatchModel matchData) { if (matchData == null) { throw new Exception("Нет данных о матче. Симуляция не работает."); } int matchId = matchData.MatchId; int gameServerPort = matchData.GameServerPort; string gameServerIp = matchData.GameServerIp; IPEndPoint serverIpEndPoint = new IPEndPoint(IPAddress.Parse(gameServerIp), gameServerPort); log.Info("Установка прослушки udp."); UdpClient udpClient = new UdpClient { Client = { Blocking = false } }; udpClient.Connect(serverIpEndPoint); udpClientWrapper = new UdpClientWrapper(udpClient); UdpSendUtils udpSendUtils = new UdpSendUtils(matchId, udpClientWrapper); return(udpSendUtils); }
public IUdpClient Create(IPEndPoint endpoint) { var client = new UdpClientWrapper(); client.Client.Bind(endpoint); return(client); }
public async Task <IEnumerable <DiscoveryDevice> > Discover(int timeout, CancellationToken cancellationToken = default) { var devices = new List <DiscoveryDevice> (); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in nics) { // Only select interfaces that are Ethernet type and support IPv4 (important to minimize waiting time) if (adapter.NetworkInterfaceType != NetworkInterfaceType.Ethernet && !adapter.NetworkInterfaceType.ToString().ToLower().StartsWith("wireless")) { continue; } if (adapter.OperationalStatus == OperationalStatus.Down) { continue; } if (adapter.Supports(NetworkInterfaceComponent.IPv4) == false) { continue; } try { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); foreach (var ua in adapterProperties.UnicastAddresses) { if (ua.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { // IPEndPoint myLocalEndPoint = new IPEndPoint(ua.Address, 0); // port does not matter UdpClientWrapper sc = new UdpClientWrapper(myLocalEndPoint); var devices1 = await Discover(timeout, sc, cancellationToken); if (devices1.Count() > 0) { devices.AddRange(devices1); } } } } catch (Exception ex) { string s = ex.Message; } } return(devices); }
/// <summary> /// Adds a sink that sends log events as UDP packages over the network. /// </summary> /// <param name="sinkConfiguration">Logger sink configuration.</param> /// <param name="remoteAddress"> /// The <see cref="IPAddress"/> of the remote host or multicast group to which the UDP /// client should sent the logging event. /// </param> /// <param name="remotePort"> /// The TCP port of the remote host or multicast group to which the UDP client should sent /// the logging event. /// </param> /// <param name="formatter"> /// Controls the rendering of log events into text, for example to log JSON. To control /// plain text formatting, use the overload that accepts an output template. /// </param> /// <param name="localPort"> /// The TCP port from which the UDP client will communicate. The default is 0 and will /// cause the UDP client not to bind to a local port. /// </param> /// <param name="restrictedToMinimumLevel"> /// The minimum level for events passed through the sink. The default is /// <see cref="LevelAlias.Minimum"/>. /// </param> /// <returns>Logger configuration, allowing configuration to continue.</returns> public static LoggerConfiguration Udp( this LoggerSinkConfiguration sinkConfiguration, IPAddress remoteAddress, int remotePort, ITextFormatter formatter, int localPort = 0, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum) { if (sinkConfiguration == null) { throw new ArgumentNullException(nameof(sinkConfiguration)); } var client = new UdpClientWrapper(localPort, remoteAddress); var sink = new UdpSink(client, remoteAddress, remotePort, formatter); return(sinkConfiguration.Sink(sink, restrictedToMinimumLevel)); }
/// <summary> /// Start listening for requests /// </summary> public void Start() { if (!Running) { Server = new UdpClientWrapper(LocalEndpoint); Running = true; //TODO log output here //$"Starting Radius server on {LocalEndpoint}" _ = StartReceiveLoopAsync(); //TODO log output here //"Server started" } else { //TODO log output here //"Server already started" } }
protected override UdpConnection CreateUdpConnection(UdpClientWrapper wrapper) { return(new GLPUdpConnection(wrapper)); }
public GLPUdpConnection(UdpClientWrapper wrapper) : base(wrapper) { }
public UdpSendUtils(int matchId, UdpClientWrapper udpClientWrapper) { this.matchId = matchId; this.udpClientWrapper = udpClientWrapper; }