本文整理汇总了C#中RegressionTests.Shared.TcpConnection.IsPortOpen方法的典型用法代码示例。如果您正苦于以下问题:C# TcpConnection.IsPortOpen方法的具体用法?C# TcpConnection.IsPortOpen怎么用?C# TcpConnection.IsPortOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RegressionTests.Shared.TcpConnection
的用法示例。
在下文中一共展示了TcpConnection.IsPortOpen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConnections
public void TestConnections()
{
var oSocket = new TcpConnection();
// Make sure an IP range exists.
RemoveIPRanges();
if (_ipRanges.Count == 0)
AddIPRange();
if (!oSocket.IsPortOpen(25))
throw new Exception("ERROR: Cannot connect to port 25");
if (!oSocket.IsPortOpen(110))
throw new Exception("ERROR: Cannot connect to port 110");
if (!oSocket.IsPortOpen(143))
throw new Exception("ERROR: Cannot connect to port 143");
RemoveIPRanges();
// Now it shouldn't be possible to connect.
if (oSocket.IsPortOpen(25))
throw new Exception("ERROR: Cannot connect to port 25");
if (oSocket.IsPortOpen(110))
throw new Exception("ERROR: Cannot connect to port 110");
if (oSocket.IsPortOpen(143))
throw new Exception("ERROR: Cannot connect to port 143");
AddIPRange();
// Now it should be possible to connect again.
if (!oSocket.IsPortOpen(25))
throw new Exception("ERROR: Cannot connect to port 25");
if (!oSocket.IsPortOpen(110))
throw new Exception("ERROR: Cannot connect to port 110");
if (!oSocket.IsPortOpen(143))
throw new Exception("ERROR: Cannot connect to port 143");
}
示例2: TestOnClientConnectVBScript
public void TestOnClientConnectVBScript()
{
Application app = SingletonProvider<TestSetup>.Instance.GetApp();
Scripting scripting = app.Settings.Scripting;
string script = "Sub OnClientConnect(oClient) " + Environment.NewLine +
" EventLog.Write(\"Port: \" & oClient.Port) " + Environment.NewLine +
" EventLog.Write(\"Address: \" & oClient.IPAddress) " + Environment.NewLine +
" EventLog.Write(\"Username: \" & oClient.Username) " + Environment.NewLine +
"End Sub" + Environment.NewLine + Environment.NewLine;
File.WriteAllText(scripting.CurrentScriptFile, script);
scripting.Enabled = true;
scripting.Reload();
string eventLogFile = app.Settings.Logging.CurrentEventLog;
if (File.Exists(eventLogFile))
File.Delete(eventLogFile);
var socket = new TcpConnection();
Assert.IsTrue(socket.IsPortOpen(25));
// Check that the message exists
string message = TestSetup.ReadExistingTextFile(eventLogFile);
Assert.IsNotEmpty(message);
Assert.IsTrue(message.Contains("Port: 25"));
Assert.IsTrue(message.Contains("Address: 127"));
Assert.IsTrue(message.Contains("Username: \"")); // Should be empty, Username isn't available at this time.
}
示例3: TestPortInUse
public void TestPortInUse()
{
Application application = SingletonProvider<TestSetup>.Instance.GetApp();
application.Stop();
var sock = new TcpConnection();
using (var serverSocket = new TcpServer(1, 25, eConnectionSecurity.eCSNone))
{
serverSocket.StartListen();
application.Start();
// make sure it's possible to connect to the non blocked port.
sock.IsPortOpen(110);
sock.IsPortOpen(143);
//let this our temp server die.
sock.IsPortOpen(25);
// make sure that hMailServer reported an error during start up because the ports were blocked.
TestSetup.AssertReportedError();
}
// restart hMailServer again. everything is now back to normal.
application.Stop();
application.Start();
sock.IsPortOpen(25);
}