/// (from System.Net.Sockets)
/// </summary>
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void TcpClient()
{
// set up a listening Socket
Socket lSock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
- lSock.Bind(new IPEndPoint(IPAddress.Any, 8765));
+ var port = NetworkHelpers.FindFreePort ();
+ lSock.Bind(new IPEndPoint(IPAddress.Any, port));
lSock.Listen(-1);
// connect to it with a TcpClient
- TcpClient outClient = new TcpClient("localhost", 8765);
+ TcpClient outClient = new TcpClient("localhost", port);
Socket inSock = lSock.Accept();
}
[Test] // bug #81105
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void CloseTest ()
{
- IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8765);
- using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
- sr.Start ();
-
- TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
+ var port = NetworkHelpers.FindFreePort ();
+ IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, port);
+ using (SocketResponder sr = new SocketResponder (localEP, s => CloseRequestHandler (s))) {
+ TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), port);
NetworkStream ns = tcpClient.GetStream ();
Assert.IsNotNull (ns, "#A1");
Assert.AreEqual (0, tcpClient.Available, "#A2");
*/
}
- using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
- sr.Start ();
-
- TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
+ using (SocketResponder sr = new SocketResponder (localEP, s => CloseRequestHandler (s))) {
+ TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), port);
Assert.AreEqual (0, tcpClient.Available, "#B1");
Assert.IsTrue (tcpClient.Connected, "#B2");
// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#B3");
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof(ArgumentNullException))]
+#endif
public void ConnectMultiNull ()
{
TcpClient client = new TcpClient ();
IPAddress[] ipAddresses = null;
- client.Connect (ipAddresses, 1234);
+ client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectMultiAny ()
{
TcpClient client = new TcpClient ();
ipAddresses[0] = IPAddress.Any;
try {
- client.Connect (ipAddresses, 1234);
+ client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
Assert.Fail ("ConnectMultiAny #1");
} catch (SocketException ex) {
Assert.AreEqual (10049, ex.ErrorCode, "ConnectMultiAny #2");
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectMultiRefused ()
{
TcpClient client = new TcpClient ();
ipAddresses[0] = IPAddress.Loopback;
try {
- client.Connect (ipAddresses, 1234);
+ client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
Assert.Fail ("ConnectMultiRefused #1");
} catch (SocketException ex) {
Assert.AreEqual (10061, ex.ErrorCode, "ConnectMultiRefused #2");
Assert.Fail ("ConnectMultiRefused #3");
}
}
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void ExclusiveAddressUse ()
+ {
+ using (TcpClient client = new TcpClient ()) {
+ client.ExclusiveAddressUse = false;
+ }
+ }
}
}