public PacketCollection QueryServer(NetworkSettings nwSettings) { if (nwSettings == null) { throw new ArgumentNullException("nwSettings"); } PacketCollection packets = new PacketCollection(); using (UdpClient client = new UdpClient(nwSettings.LocalPort)) { byte[] request, response, timestamp = Helpers.GetTimeStamp(); IPEndPoint remoteIpEndpoint = new IPEndPoint(IPAddress.Parse(nwSettings.Host), nwSettings.RemotePort); client.Client.ReceiveTimeout = nwSettings.ReceiveTimeout; client.Connect(remoteIpEndpoint); request = GetChallengeRequest(timestamp); client.Send(request, request.Length); response = client.Receive(ref remoteIpEndpoint); ChallengePacket pChallenge = new ChallengePacket(response); request = GetInfosRequest(timestamp, pChallenge.GetChallenge()); client.Send(request, request.Length); while (true) { try { response = client.Receive(ref remoteIpEndpoint); packets.Add(new InfoPacket(response)); } catch (SocketException ex) { if (ex.ErrorCode == (int)SocketError.TimedOut) { break; } else { throw; } } } } return(packets); }
public PacketCollection QueryServer(NetworkSettings nwSettings) { if (nwSettings == null) throw new ArgumentNullException("nwSettings"); PacketCollection packets = new PacketCollection(); using (UdpClient client = new UdpClient(nwSettings.LocalPort)) { byte[] request, response, timestamp = Helpers.GetTimeStamp(); IPEndPoint remoteIpEndpoint = new IPEndPoint(IPAddress.Parse(nwSettings.Host), nwSettings.RemotePort); client.Client.ReceiveTimeout = nwSettings.ReceiveTimeout; client.Connect(remoteIpEndpoint); request = GetChallengeRequest(timestamp); client.Send(request, request.Length); response = client.Receive(ref remoteIpEndpoint); ChallengePacket pChallenge = new ChallengePacket(response); request = GetInfosRequest(timestamp, pChallenge.GetChallenge()); client.Send(request, request.Length); while (true) { try { response = client.Receive(ref remoteIpEndpoint); packets.Add(new InfoPacket(response)); } catch (SocketException ex) { if (ex.ErrorCode == (int)SocketError.TimedOut) break; else throw; } } } return packets; }