|
|
|
|
@ -9,7 +9,7 @@ public class Program |
|
|
|
|
private static StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; |
|
|
|
|
private static bool _continue; |
|
|
|
|
private static Thread readThread; |
|
|
|
|
private static UdpClient udpClient = null; |
|
|
|
|
private static UdpClient udpClient = null, receivingUdpClient = null; |
|
|
|
|
|
|
|
|
|
public static bool applicationQuitRequested { get; private set; } |
|
|
|
|
|
|
|
|
|
@ -52,12 +52,13 @@ public class Program |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
udpClient = new UdpClient(11000); |
|
|
|
|
udpClient = new UdpClient(); |
|
|
|
|
receivingUdpClient = new UdpClient(11001); |
|
|
|
|
udpClient.Connect(hostname, port); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine($"Could not connect to endpoint."); |
|
|
|
|
Console.WriteLine($"Could not create UDP client. \n {ex}"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -97,6 +98,8 @@ public class Program |
|
|
|
|
readThread.Join(TimeSpan.FromSeconds(2)); |
|
|
|
|
//readThread.Abort(); |
|
|
|
|
readThread = null; |
|
|
|
|
receivingUdpClient.Close(); |
|
|
|
|
receivingUdpClient = null; |
|
|
|
|
udpClient.Close(); |
|
|
|
|
udpClient = null; |
|
|
|
|
Console.WriteLine("Closed connection."); |
|
|
|
|
@ -128,7 +131,7 @@ public class Program |
|
|
|
|
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); |
|
|
|
|
|
|
|
|
|
// Blocks until a message returns on this socket from a remote host. |
|
|
|
|
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); |
|
|
|
|
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint); |
|
|
|
|
string returnData = Encoding.ASCII.GetString(receiveBytes); |
|
|
|
|
|
|
|
|
|
// Uses the IPEndPoint object to determine which of these two hosts responded. |
|
|
|
|
|