Merge pull request #375 from atomia/master
[mono.git] / mcs / class / System / Test / System.Net.Sockets / UdpClientTest.cs
index 1b1c30b55db2899cc9ecf853ac6c19d0d1988e2a..2062cf84f62b9ab07d4f4783d02404c07b314480 100644 (file)
@@ -389,7 +389,9 @@ namespace MonoTests.System.Net.Sockets {
                        Socket s;
                        IPEndPoint localEP;
 
-                       client = new MyUdpClient ("localhost", IPEndPoint.MinPort);
+                       // Bug #5503
+                       // UDP port 0 doesn't seem to be valid.
+                       client = new MyUdpClient ("127.0.0.1", 53);
                        s = client.Client;
                        Assert.IsNotNull (s, "#A:Client");
                        Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
@@ -412,7 +414,7 @@ namespace MonoTests.System.Net.Sockets {
                        Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#A:Client:LocalEndPoint/Address");
                        Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
 
-                       client = new MyUdpClient ("localhost", IPEndPoint.MaxPort);
+                       client = new MyUdpClient ("127.0.0.1", IPEndPoint.MaxPort);
                        s = client.Client;
                        Assert.IsNotNull (s, "#B:Client");
                        Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#B:Client:AddressFamily");
@@ -479,7 +481,7 @@ namespace MonoTests.System.Net.Sockets {
                [Test]
                public void UdpClientBroadcastTest () 
                {
-                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234));
+                       UdpClient client = new UdpClient ();
                        byte[] bytes = new byte[] {10, 11, 12, 13};
 
                        try {
@@ -899,7 +901,19 @@ namespace MonoTests.System.Net.Sockets {
                [Test]
                public void CloseInReceive ()
                {
-                       UdpClient client = new UdpClient (50000);
+                       UdpClient client = null;
+                       var rnd = new Random ();
+                       for (int i = 0; i < 5; i++) {
+                               int port = rnd.Next (1025, 65534);
+                               try {
+                                       client = new UdpClient (port);
+                                       break;
+                               } catch (Exception ex) {
+                                       if (i == 5)
+                                               throw;
+                               }
+                       }
+
                        new Thread(delegate() {
                                Thread.Sleep(2000);
                                client.Close();