public void TestSendViaClosedSocket() { NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); testRemoteSocketState.TheSocket.Close(); //Sending null value, should causes a Error in the RemoteState Assert.IsFalse(Networking.Send(testRemoteSocketState.TheSocket, null)); }
public void TestConnect() { NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState, 2112); Assert.IsTrue(testRemoteSocketState.TheSocket.Connected); Assert.IsTrue(testLocalSocketState.TheSocket.Connected); Assert.AreEqual("127.0.0.1:2112", testLocalSocketState.TheSocket.RemoteEndPoint.ToString()); }
public void TestStopServer() { NetworkTestHelper.SetupSingleConnectionTest( out testListener, out testRemoteSocketState, out testLocalSocketState, 2200); Networking.StopServer(testListener); SocketState newState = new SocketState(null, null); Networking.ConnectToServer(s => newState = s, "localhost", 2200); NetworkTestHelper.WaitForOrTimeout(() => false, 3000); Assert.IsTrue(newState.ErrorOccured); }
public void TestClose() { NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); Networking.StopServer(testListener); SocketState client = null; void SaveClient(SocketState s) { client = s; } //Using port 2112 because it is the same port being used in SetupSingleConnectionTest method use //Should produce a ErrorOccured SocketState because we have closed hearing any incoming connections Networking.ConnectToServer(SaveClient, "localhost", 2112); Assert.IsTrue(client.ErrorOccured); }
public void TestConnectToServerinvaildIPadress() { bool isCalled = false; void saveClientState(SocketState x) { isCalled = true; testLocalSocketState = x; } NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); Networking.ConnectToServer(saveClientState, "3731:54:65fe:2: :a7/64", 2112); NetworkTestHelper.WaitForOrTimeout(() => isCalled, NetworkTestHelper.timeout); Assert.IsTrue(isCalled); Assert.IsTrue(testLocalSocketState.ErrorOccured); }
public void TestConnectToServerIPV4Address() { bool isCalled = false; void saveClientState(SocketState x) { isCalled = true; testLocalSocketState = x; } NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); Networking.ConnectToServer(saveClientState, "192.168.0.19", 2112); NetworkTestHelper.WaitForOrTimeout(() => isCalled, 1000); Assert.IsTrue(isCalled); Assert.IsTrue(testLocalSocketState.ErrorOccured); }
public void TestConnectStartAndStopNoServer() { bool isCalled = false; void saveClientState(SocketState x) { isCalled = true; testLocalSocketState = x; } NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); Networking.StopServer(testListener); // Try to connect without setting up a server first. Networking.ConnectToServer(saveClientState, "localhost", 2112); NetworkTestHelper.WaitForOrTimeout(() => isCalled, NetworkTestHelper.timeout); Assert.IsTrue(isCalled); Assert.IsTrue(testLocalSocketState.ErrorOccured); }
public void SetupTestConnections(bool clientSide, out TcpListener listener, out SocketState local, out SocketState remote) { if (clientSide) { NetworkTestHelper.SetupSingleConnectionTest( out listener, out local, // local becomes client out remote); // remote becomes server } else { NetworkTestHelper.SetupSingleConnectionTest( out listener, out remote, // remote becomes client out local); // local becomes server } Assert.IsNotNull(local); Assert.IsNotNull(remote); }
public void TestShutDownSocketState() { NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); testLocalSocketState.OnNetworkAction = x => { if (x.ErrorOccured) { return; } Networking.GetData(x); }; //Server Ready to receive data Networking.GetData(testLocalSocketState); //Shutting down RemoteSocket (sending), this should cause LocalSocket to receive 0 byte in EndReceive call, which will result in Error testRemoteSocketState.TheSocket.Shutdown(SocketShutdown.Both); NetworkTestHelper.WaitForOrTimeout(() => false, NetworkTestHelper.timeout); //Since remote is shut down this should receive 0 bytes, should causes a Error in the LocalState Assert.IsTrue(testLocalSocketState.ErrorOccured); }
public void TestConnectToServerIPV6Address() { bool isCalled = false; void saveClientState(SocketState x) { isCalled = true; testLocalSocketState = x; } NetworkTestHelper.SetupSingleConnectionTest(out testListener, out testLocalSocketState, out testRemoteSocketState); Networking.ConnectToServer(saveClientState, "2602:41:8182:68ff:58ec:52fc:8711:b430", 2112); // Networking.ConnectToServer(saveClientState, "fd00::58ec:52fc:8711:b430", 2112); //Networking.ConnectToServer(saveClientState, "2001:0db8:85a3:0000:0000:8a2e:0370:7334", 2112); NetworkTestHelper.WaitForOrTimeout(() => isCalled, 1000); Assert.IsTrue(isCalled); Assert.IsTrue(testLocalSocketState.ErrorOccured); }