| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- // System.Net.Sockets.UdpClientTest.cs
- //
- // Authors:
- // Chris Bacon <[email protected]>
- // Gert Driesen <[email protected]>
- //
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- using System.Threading.Tasks;
- using NUnit.Framework;
- namespace MonoTests.System.Net.Sockets {
- [TestFixture]
- public class UdpClientTest {
- [Test] // .ctor ()
- public void Constructor1 ()
- {
- MyUdpClient client;
- Socket s;
- client = new MyUdpClient ();
- s = client.Client;
- Assert.IsNotNull (s, "Client");
- Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "Client:AddressFamily");
- Assert.IsFalse (s.Connected, "Client:Connected");
- Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
- Assert.IsNull (s.LocalEndPoint, "Client:LocalEndPoint");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "Client:ProtocolType");
- Assert.IsNull (s.RemoteEndPoint, "Client:RemoteEndPoint");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "Client:SocketType");
- Assert.IsFalse (client.Active, "Active");
- Assert.IsFalse (client.DontFragment, "DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "Ttl");
- client.Close ();
- }
- [Test] // .ctor (AddressFamily)
- public void Constructor2 ()
- {
- MyUdpClient client;
- Socket s;
- client = new MyUdpClient (AddressFamily.InterNetwork);
- s = client.Client;
- Assert.IsNotNull (s, "#A:Client");
- Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#A:Client:Connected");
- Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
- Assert.IsNull (s.LocalEndPoint, "#A:Client:LocalEndPoint");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
- Assert.IsNull (s.RemoteEndPoint, "#A:Client:RemoteEndPoint");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
- Assert.IsFalse (client.Active, "#A:Active");
- //Assert.IsFalse (client.DontFragment, "#A:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- client = new MyUdpClient (AddressFamily.InterNetworkV6);
- s = client.Client;
- Assert.IsNotNull (s, "#B:Client");
- Assert.AreEqual (AddressFamily.InterNetworkV6, s.AddressFamily, "#B:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#B:Client:Connected");
- Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
- Assert.IsNull (s.LocalEndPoint, "#B:Client:LocalEndPoint");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
- Assert.IsNull (s.RemoteEndPoint, "#B:Client:RemoteEndPoint");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
- Assert.IsFalse (client.Active, "#B:Active");
- //Assert.IsFalse (client.DontFragment, "#B:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
- client.Close ();
- }
- [Test] // .ctor (AddressFamily)
- public void Constructor2_Family_Invalid ()
- {
- try {
- new UdpClient (AddressFamily.NetBios);
- Assert.Fail ("#A1");
- } catch (ArgumentException ex) {
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- // 'UDP' Client can only accept InterNetwork or InterNetworkV6
- // addresses
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("family", ex.ParamName, "#A5");
- }
- try {
- new UdpClient ((AddressFamily) 666);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.AreEqual ("family", ex.ParamName, "#B5");
- }
- }
- [Test] // .ctor (Int32)
- public void Constructor3 ()
- {
- Socket s;
- IPEndPoint localEP;
- using (MyUdpClient client = new MyUdpClient (IPEndPoint.MinPort))
- {
- s = client.Client;
- Assert.IsNotNull (s, "#A:Client");
- Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#A:Client:Connected");
- Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
- Assert.IsFalse (client.Active, "#A:Active");
- Assert.IsFalse (client.DontFragment, "#A:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
- Assert.AreEqual (IPAddress.Any, localEP.Address, "#A:Client:LocalEndPoint/Address");
- Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
- }
- using (MyUdpClient client = new MyUdpClient (IPEndPoint.MaxPort))
- {
- s = client.Client;
- Assert.IsNotNull (s, "#B:Client");
- Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#B:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#B:Client:Connected");
- Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
- Assert.IsFalse (client.Active, "#B:Active");
- Assert.IsFalse (client.DontFragment, "#B:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
- Assert.AreEqual (IPAddress.Any, localEP.Address, "#B:Client:LocalEndPoint/Address");
- Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#B:Client:LocalEndPoint/AddressFamily");
- Assert.AreEqual (IPEndPoint.MaxPort, localEP.Port, "#B:Client:LocalEndPoint/Port");
- }
- }
- [Test] // .ctor (Int32)
- public void Constructor3_Port_OutOfRange ()
- {
- try {
- new UdpClient (IPEndPoint.MaxPort + 1);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- // Specified argument was out of the range of valid values
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("port", ex.ParamName, "#A5");
- }
- try {
- new UdpClient (IPEndPoint.MinPort - 1);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- // Specified argument was out of the range of valid values
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("port", ex.ParamName, "#A5");
- }
- }
- [Test] // .ctor (IPEndPoint)
- public void Constructor4 ()
- {
- Socket s;
- IPEndPoint localEP;
- IPEndPoint clientEP;
- clientEP = new IPEndPoint (IPAddress.Loopback, 8001);
- using (MyUdpClient client = new MyUdpClient (clientEP))
- {
- s = client.Client;
- Assert.IsNotNull (s, "#A:Client");
- Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#A:Client:Connected");
- Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
- Assert.IsFalse (client.Active, "#A:Active");
- Assert.IsFalse (client.DontFragment, "#A:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
- Assert.IsFalse (object.ReferenceEquals (clientEP, localEP), "#A:Client:LocalEndPoint/ReferenceEquality");
- Assert.AreEqual (clientEP.Address, localEP.Address, "#A:Client:LocalEndPoint/Address");
- Assert.AreEqual (clientEP.AddressFamily, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
- Assert.AreEqual (clientEP.Port, localEP.Port, "#A:Client:LocalEndPoint/Port");
- }
- }
- [Test] // .ctor (IPEndPoint)
- public void Constructor4_LocalEP_Null ()
- {
- try {
- new UdpClient ((IPEndPoint) null);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("localEP", ex.ParamName, "#5");
- }
- }
- [Test] // .ctor (Int32, AddressFamily)
- public void Constructor5 ()
- {
- Socket s;
- IPEndPoint localEP;
- using (MyUdpClient client = new MyUdpClient (IPEndPoint.MinPort, AddressFamily.InterNetwork))
- {
- s = client.Client;
- Assert.IsNotNull (s, "#A:Client");
- Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#A:Client:Connected");
- Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
- Assert.IsFalse (client.Active, "#A:Active");
- //Assert.IsFalse (client.DontFragment, "#A:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
- Assert.AreEqual (IPAddress.Any, localEP.Address, "#A:Client:LocalEndPoint/Address");
- Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
- }
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- using (MyUdpClient client = new MyUdpClient (IPEndPoint.MaxPort, AddressFamily.InterNetworkV6))
- {
- s = client.Client;
- Assert.IsNotNull (s, "#B:Client");
- Assert.AreEqual (AddressFamily.InterNetworkV6, s.AddressFamily, "#B:Client:AddressFamily");
- Assert.IsFalse (s.Connected, "#B:Client:Connected");
- Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
- Assert.IsFalse (client.Active, "#B:Active");
- //Assert.IsFalse (client.DontFragment, "#B:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
- Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
- Assert.AreEqual (IPAddress.IPv6Any, localEP.Address, "#B:Client:LocalEndPoint/Address");
- Assert.AreEqual (AddressFamily.InterNetworkV6, localEP.AddressFamily, "#B:Client:LocalEndPoint/AddressFamily");
- Assert.AreEqual (IPEndPoint.MaxPort, localEP.Port, "#B:Client:LocalEndPoint/Port");
- }
- }
- [Test] // .ctor (Int32, AddressFamily)
- public void Constructor5_Family_Invalid ()
- {
- try {
- new UdpClient (80, AddressFamily.NetBios);
- Assert.Fail ("#A1");
- } catch (ArgumentException ex) {
- // family
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- // 'UDP' Client can only accept InterNetwork or InterNetworkV6
- // addresses
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("family", ex.ParamName, "#A5");
- }
- try {
- new UdpClient (80, (AddressFamily) 666);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // family
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- // 'UDP' Client can only accept InterNetwork or InterNetworkV6
- // addresses
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.AreEqual ("family", ex.ParamName, "#B5");
- }
- }
- [Test] // .ctor (Int32, AddressFamily)
- public void Constructor5_Port_OutOfRange ()
- {
- try {
- new UdpClient (IPEndPoint.MaxPort + 1, AddressFamily.InterNetwork);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- // Specified argument was out of the range of valid values
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("port", ex.ParamName, "#A5");
- }
- try {
- new UdpClient (IPEndPoint.MinPort - 1, AddressFamily.InterNetwork);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- // Specified argument was out of the range of valid values
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("port", ex.ParamName, "#A5");
- }
- }
- [Test] // .ctor (String, Int32)
- public void Constructor6 ()
- {
- Socket s;
- IPEndPoint localEP;
- // Bug #5503
- // UDP port 0 doesn't seem to be valid.
- using (MyUdpClient 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");
- Assert.IsTrue (s.Connected, "#A:Client:Connected");
- Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
- Assert.IsTrue (client.Active, "#A:Active");
- Assert.IsFalse (client.DontFragment, "#A:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
- //Assert.IsFalse (client.MulticastLoopback, "#A:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
- Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#A:Client:LocalEndPoint/Address");
- Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
- }
- using (MyUdpClient 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");
- Assert.IsTrue (s.Connected, "#B:Client:Connected");
- Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
- Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
- Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
- Assert.IsTrue (client.Active, "#B:Active");
- Assert.IsFalse (client.DontFragment, "#B:DontFragment");
- Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
- //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
- //Assert.IsFalse (client.MulticastLoopback, "#B:MulticastLoopback");
- //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
- localEP = s.LocalEndPoint as IPEndPoint;
- Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
- Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#B:Client:LocalEndPoint/Address");
- Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#B:Client:LocalEndPoint/AddressFamily");
- }
- }
- [Test] // .ctor (String, Int32)
- public void Constructor6_HostName_Null ()
- {
- try {
- new UdpClient ((string) null, int.MaxValue);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("hostname", ex.ParamName, "#5");
- }
- }
- [Test] // .ctor (String, Int32)
- public void Constructor6_Port_OutOfRange ()
- {
- try {
- new UdpClient ("local", IPEndPoint.MaxPort + 1);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- // Specified argument was out of the range of valid values
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("port", ex.ParamName, "#A5");
- }
- try {
- new UdpClient ("local", IPEndPoint.MinPort - 1);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- // Specified argument was out of the range of valid values
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.AreEqual ("port", ex.ParamName, "#A5");
- }
- }
- [Test]
- public void UdpClientBroadcastTest ()
- {
- UdpClient client = new UdpClient ();
- byte[] bytes = new byte[] {10, 11, 12, 13};
- try {
- client.Send (bytes, bytes.Length, new IPEndPoint (IPAddress.Broadcast, 1235));
- } finally {
- client.Close ();
- }
- }
- [Test] // JoinMulticastGroup (IPAddress)
- public void JoinMulticastGroup1_IPv4 ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr);
- }
- }
- [Test] // JoinMulticastGroup (IPAddress)
- public void JoinMulticastGroup1_IPv6 ()
- {
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr);
- }
- }
- [Test] // JoinMulticastGroup (IPAddress)
- public void JoinMulticastGroup1_MulticastAddr_Null ()
- {
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
- try {
- client.JoinMulticastGroup ((IPAddress) null);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("multicastAddr", ex.ParamName, "#5");
- }
- }
- }
- [Test] // JoinMulticastGroup (IPAddress)
- public void JoinMulticastGroup1_Socket_Closed ()
- {
- IPAddress mcast_addr = null;
- UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234));
- client.Close ();
- try {
- client.JoinMulticastGroup (mcast_addr);
- Assert.Fail ("#1");
- } catch (ObjectDisposedException ex) {
- // Cannot access a disposed object
- Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual (typeof (UdpClient).FullName, ex.ObjectName, "#5");
- }
- }
- [Test] // JoinMulticastGroup (IPAddress)
- [Category ("NotWorking")]
- public void JoinMulticastGroup1_Socket_NotBound ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- UdpClient client = new UdpClient (AddressFamily.InterNetwork);
- try {
- client.JoinMulticastGroup (mcast_addr);
- Assert.Fail ("#1");
- } catch (SocketException ex) {
- // An invalid argument was supplied
- Assert.AreEqual (typeof (SocketException), ex.GetType (), "#2");
- Assert.AreEqual (10022, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
- Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
- } finally {
- client.Close ();
- }
- }
- [Test] // JoinMulticastGroup (In32, IPAddress)
- public void JoinMulticastGroup2_IPv4 ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
- try {
- client.JoinMulticastGroup (0, mcast_addr);
- Assert.Fail ("#1");
- } catch (SocketException ex) {
- // The attempted operation is not supported for the type of
- // object referenced
- Assert.AreEqual (typeof (SocketException), ex.GetType (), "#2");
- Assert.AreEqual (10045, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (10045, ex.NativeErrorCode, "#6");
- Assert.AreEqual (SocketError.OperationNotSupported, ex.SocketErrorCode, "#7");
- }
- }
- }
- [Test] // JoinMulticastGroup (In32, IPAddress)
- public void JoinMulticastGroup2_IPv6 ()
- {
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
- client.JoinMulticastGroup (0, mcast_addr);
- }
- }
- [Test] // JoinMulticastGroup (Int32, IPAddress)
- public void JoinMulticastGroup2_MulticastAddr_Null ()
- {
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
- try {
- client.JoinMulticastGroup (0, (IPAddress) null);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("multicastAddr", ex.ParamName, "#5");
- }
- }
- }
- [Test] // JoinMulticastGroup (Int32, IPAddress)
- public void JoinMulticastGroup2_Socket_Closed ()
- {
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- IPAddress mcast_addr = null;
- UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234));
- client.Close ();
- try {
- client.JoinMulticastGroup (0, mcast_addr);
- Assert.Fail ("#1");
- } catch (ObjectDisposedException ex) {
- // Cannot access a disposed object
- Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual (typeof (UdpClient).FullName, ex.ObjectName, "#5");
- }
- }
- [Test] // JoinMulticastGroup (Int32, IPAddress)
- [Category ("NotWorking")]
- public void JoinMulticastGroup2_Socket_NotBound ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
- UdpClient client = new UdpClient (AddressFamily.InterNetworkV6);
- try {
- client.JoinMulticastGroup (0, mcast_addr);
- Assert.Fail ("#1");
- } catch (SocketException ex) {
- // An invalid argument was supplied
- Assert.AreEqual (typeof (SocketException), ex.GetType (), "#2");
- Assert.AreEqual (10022, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
- Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
- } finally {
- client.Close ();
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, Int32)
- public void JoinMulticastGroup3_IPv4 ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr, 0);
- }
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr, 255);
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, Int32)
- public void JoinMulticastGroup3_IPv6 ()
- {
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr, 0);
- }
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr, 255);
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, Int32)
- public void JoinMulticastGroup3_MulticastAddr_Null ()
- {
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
- try {
- client.JoinMulticastGroup ((IPAddress) null, int.MaxValue);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("multicastAddr", ex.ParamName, "#5");
- }
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, Int32)
- public void JoinMulticastGroup3_Socket_Closed ()
- {
- IPAddress mcast_addr = null;
- UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234));
- client.Close ();
- try {
- client.JoinMulticastGroup (mcast_addr, 0);
- Assert.Fail ("#1");
- } catch (ObjectDisposedException ex) {
- // Cannot access a disposed object
- Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual (typeof (UdpClient).FullName, ex.ObjectName, "#5");
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, Int32)
- [Category ("NotWorking")]
- public void JoinMulticastGroup3_Socket_NotBound ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- UdpClient client = new UdpClient (AddressFamily.InterNetwork);
- try {
- client.JoinMulticastGroup (mcast_addr, 5);
- Assert.Fail ("#1");
- } catch (SocketException ex) {
- // An invalid argument was supplied
- Assert.AreEqual (typeof (SocketException), ex.GetType (), "#2");
- Assert.AreEqual (10022, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
- Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
- } finally {
- client.Close ();
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, IPAddress)
- public void JoinMulticastGroup4_IPv4 ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- IPAddress local_addr = IPAddress.Any;
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
- client.JoinMulticastGroup (mcast_addr, local_addr);
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, IPAddress)
- public void JoinMulticastGroup4_IPv6 ()
- {
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
- IPAddress local_addr = IPAddress.IPv6Any;
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
- try {
- client.JoinMulticastGroup (mcast_addr, local_addr);
- Assert.Fail ("#1");
- } catch (SocketException ex) {
- // The attempted operation is not supported for the type of
- // object referenced
- Assert.AreEqual (typeof (SocketException), ex.GetType (), "#2");
- Assert.AreEqual (10045, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (10045, ex.NativeErrorCode, "#6");
- Assert.AreEqual (SocketError.OperationNotSupported, ex.SocketErrorCode, "#7");
- }
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, IPAddress)
- public void JoinMulticastGroup4_LocalAddress_Null ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
- try {
- client.JoinMulticastGroup (mcast_addr, (IPAddress) null);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("mcint", ex.ParamName, "#5");
- }
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, IPAddress)
- public void JoinMulticastGroup4_MulticastAddr_Null ()
- {
- using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
- try {
- client.JoinMulticastGroup ((IPAddress) null, IPAddress.Loopback);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("group", ex.ParamName, "#5");
- }
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, IPAddress)
- public void JoinMulticastGroup4_Socket_Closed ()
- {
- IPAddress mcast_addr = null;
- IPAddress local_addr = null;
- UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234));
- client.Close ();
- try {
- client.JoinMulticastGroup (mcast_addr, local_addr);
- Assert.Fail ("#1");
- } catch (ObjectDisposedException ex) {
- // Cannot access a disposed object
- Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual (typeof (UdpClient).FullName, ex.ObjectName, "#5");
- }
- }
- [Test] // JoinMulticastGroup (IPAddress, IPAddress)
- [Category ("NotWorking")]
- public void JoinMulticastGroup4_Socket_NotBound ()
- {
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
- IPAddress local_addr = Dns.GetHostEntry (string.Empty).AddressList [0];
- UdpClient client = new UdpClient (AddressFamily.InterNetwork);
- try {
- client.JoinMulticastGroup (mcast_addr, local_addr);
- Assert.Fail ("#1");
- } catch (SocketException ex) {
- // An invalid argument was supplied
- Assert.AreEqual (typeof (SocketException), ex.GetType (), "#2");
- Assert.AreEqual (10022, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
- Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
- } finally {
- client.Close ();
- }
- }
- [Test]
- public void CloseInReceive ()
- {
- UdpClient client = null;
- var rnd = new Random ();
- for (int i = 0, max = 5; i < max; i++) {
- int port = rnd.Next (1025, 65534);
- try {
- client = new UdpClient (port);
- break;
- } catch (Exception) {
- if (i == max - 1)
- throw;
- }
- }
- ManualResetEvent ready = new ManualResetEvent (false);
- bool got_exc = false;
- Task receive_task = Task.Factory.StartNew (() => {
- IPEndPoint ep = new IPEndPoint (IPAddress.Any, 0);
- try {
- ready.Set ();
- client.Receive(ref ep);
- } catch (SocketException) {
- got_exc = true;
- } finally {
- client.Close ();
- }
- });
- ready.WaitOne (2000);
- Thread.Sleep (20);
- client.Close();
- Assert.IsTrue (receive_task.Wait (1000));
- Assert.IsTrue (got_exc);
- }
- // Test for bug 324033
- [Test]
- public void JoinMulticastGroupWithLocal ()
- {
- UdpClient client = new UdpClient (9001);
- IPAddress mcast_addr = IPAddress.Parse ("224.0.0.24");
- IPAddress local_addr = IPAddress.Any;
- try {
- client.JoinMulticastGroup (mcast_addr, local_addr);
- } finally {
- client.Close ();
- }
- }
-
- [Test]
- [ExpectedException (typeof(ArgumentNullException))]
- public void BeginSendNull ()
- {
- UdpClient client = new UdpClient ();
- client.BeginSend (null, 0, null, null);
- client.Close ();
- }
-
- static bool BSSent = false;
- static int BSBytes;
- static ManualResetEvent BSCalledBack = new ManualResetEvent (false);
-
- private static void BSCallback (IAsyncResult asyncResult)
- {
- UdpClient client = (UdpClient)asyncResult.AsyncState;
-
- BSBytes = client.EndSend (asyncResult);
-
- BSSent = true;
- BSCalledBack.Set ();
- }
-
- [Test]
- public void BeginSend ()
- {
- UdpClient client = new UdpClient ();
- byte[] bytes = new byte[] {10, 11, 12, 13};
- try {
- client.BeginSend (bytes, bytes.Length, new AsyncCallback (BSCallback), client);
- Assert.Fail ("BeginSend #1");
- } catch (SocketException ex) {
- Assert.AreEqual (10057, ex.ErrorCode,
- "BeginSend #2");
- }
-
- try {
- client.BeginSend (bytes, bytes.Length, null, new AsyncCallback (BSCallback), client);
- Assert.Fail ("BeginSend #3");
- } catch (SocketException ex) {
- Assert.AreEqual (10057, ex.ErrorCode,
- "BeginSend #4");
- }
- IPEndPoint ep = new IPEndPoint (Dns.GetHostEntry (string.Empty).AddressList[0], 1236);
-
- BSCalledBack.Reset ();
-
- client.BeginSend (bytes, bytes.Length, ep,
- new AsyncCallback (BSCallback),
- client);
- if (BSCalledBack.WaitOne (2000, false) == false) {
- Assert.Fail ("BeginSend wait timed out");
- }
-
- Assert.AreEqual (true, BSSent, "BeginSend #5");
- Assert.AreEqual (4, BSBytes, "BeginSend #6");
- client.Close ();
- }
-
- static bool BRReceived = false;
- static byte[] BRBytes;
- static IPEndPoint BRFrom;
- static ManualResetEvent BRCalledBack = new ManualResetEvent (false);
-
- private static void BRCallback (IAsyncResult asyncResult)
- {
- UdpClient client = (UdpClient)asyncResult.AsyncState;
-
- BRBytes = client.EndReceive (asyncResult, ref BRFrom);
-
- BRReceived = true;
- BRCalledBack.Set ();
- }
-
- [Test]
- public void BeginReceive ()
- {
- UdpClient client = new UdpClient (1237);
-
- BRCalledBack.Reset ();
-
- client.BeginReceive (BRCallback, client);
- IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1237);
- byte[] send_bytes = new byte[] {10, 11, 12, 13};
- client.Send (send_bytes, send_bytes.Length, ep);
- if (BRCalledBack.WaitOne (2000, false) == false) {
- Assert.Fail ("BeginReceive wait timed out");
- }
-
- Assert.AreEqual (true, BRReceived, "BeginReceive #1");
- Assert.AreEqual (4, BRBytes.Length, "BeginReceive #2");
- Assert.AreEqual (ep. Port, BRFrom.Port, "BeginReceive #3");
- Assert.AreEqual (ep.Address, BRFrom.Address, "BeginReceive #4");
- client.Close ();
- }
-
- [Test]
- public void Available ()
- {
- using (UdpClient client = new UdpClient (1238)) {
- IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1238);
- byte[] bytes = new byte[] {10, 11, 12, 13};
-
- int res = client.Send (bytes, bytes.Length, ep);
- Assert.AreEqual (bytes.Length, res, "Send");
- // that might happen too quickly, data sent and not yet received/available
- Thread.Sleep (100);
- int avail = client.Available;
-
- Assert.AreEqual (bytes.Length, avail, "Available #1");
- client.Close ();
- }
- }
-
- [Test]
- [Category ("NotWorking")] // Using PMTU settings workaround on Linux, default true
- public void DontFragmentDefault ()
- {
- UdpClient client = new UdpClient ();
-
- /* Ignore the docs, testing shows the default
- * here is in fact false
- */
- Assert.AreEqual (false, client.DontFragment, "DontFragmentDefault");
- client.Close ();
- }
-
- [Test]
- public void EnableBroadcastDefault ()
- {
- UdpClient client = new UdpClient ();
-
- Assert.AreEqual (false, client.EnableBroadcast, "EnableBroadcastDefault");
- client.Close ();
- }
-
- /* Can't test the default for ExclusiveAddressUse as
- * it's different on different versions and service
- * packs of windows
- */
- [Test]
- [Category ("NotWorking")] // Not supported on Linux
- public void ExclusiveAddressUseUnbound ()
- {
- UdpClient client = new UdpClient ();
- client.ExclusiveAddressUse = true;
- Assert.AreEqual (true, client.ExclusiveAddressUse, "ExclusiveAddressUseUnbound");
- client.Close ();
- }
-
- [Test]
- [ExpectedException (typeof(InvalidOperationException))]
- [Category ("NotWorking")] // Not supported on Linux
- public void ExclusiveAddressUseBound ()
- {
- UdpClient client = new UdpClient (1239);
- client.ExclusiveAddressUse = true;
- client.Close ();
- }
-
- [Test]
- public void MulticastLoopbackDefault ()
- {
- UdpClient client = new UdpClient ();
-
- Assert.AreEqual (true, client.MulticastLoopback, "MulticastLoopbackDefault");
- client.Close ();
- }
- [Test] // #6057
- public void ReceiveIPv6 ()
- {
- if (!Socket.OSSupportsIPv6)
- Assert.Ignore ("IPv6 not enabled.");
- int PORT = 9997;
- using(var udpClient = new UdpClient (PORT, AddressFamily.InterNetworkV6))
- using(var udpClient2 = new UdpClient (PORT+1, AddressFamily.InterNetworkV6))
- {
- var dataSent = new byte [] {1,2,3};
- udpClient2.SendAsync (dataSent, dataSent.Length, "::1", PORT);
- IPEndPoint endPoint = new IPEndPoint (IPAddress.IPv6Any, 0);
- var data = udpClient.Receive (ref endPoint);
- Assert.AreEqual (dataSent.Length, data.Length);
- }
- }
-
- /* No test for Ttl default as it is platform dependent */
- class MyUdpClient : UdpClient
- {
- public MyUdpClient ()
- {
- }
- public MyUdpClient (AddressFamily family)
- : base (family)
- {
- }
- public MyUdpClient (Int32 port)
- : base (port)
- {
- }
- public MyUdpClient (IPEndPoint localEP)
- : base (localEP)
- {
- }
- public MyUdpClient (int port, AddressFamily family)
- : base (port, family)
- {
- }
- public MyUdpClient (string hostname, int port)
- : base (hostname, port)
- {
- }
- public new bool Active {
- get { return base.Active; }
- set { base.Active = value; }
- }
- }
- }
- }
|