本文整理匯總了C#中Server.Server.onSecundaryServerFailure方法的典型用法代碼示例。如果您正苦於以下問題:C# Server.onSecundaryServerFailure方法的具體用法?C# Server.onSecundaryServerFailure怎麽用?C# Server.onSecundaryServerFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Server.Server
的用法示例。
在下文中一共展示了Server.onSecundaryServerFailure方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
public static void Main(string[] args)
{
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
bool portAvailable;
bool portFound = false;
Random rdm = new Random();
int port = rdm.Next(2001, 2100);
while (!portFound)
{
portAvailable = true;
foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
{
if (tcpi.LocalEndPoint.Port == port)
{
portAvailable = false;
break;
}
}
if (portAvailable)
{
portFound = true;
}
else
{
port = rdm.Next(2001, 2100);
}
}
TcpChannel serverChannel = new TcpChannel(port);
ChannelServices.RegisterChannel(serverChannel, false);
string serverURL = "tcp://localhost:" + port + "/" + Constants.SERVER_NAME;
System.Console.Title = serverURL;
Server server = new Server(serverURL);
RemotingServices.Marshal(server, Constants.SERVER_NAME, typeof(iServer));
server.registerInMaster();
if (server.getStatus().Equals(Constants.STATUS_PRIMARY))
{
server.launchNewServer();
}
new Thread(delegate()
{
while (true)
{
Thread t = new Thread(server.sendData);
t.Start();
if (!t.Join(TimeSpan.FromSeconds(Constants.TIMEOUT)))
{
t.Abort();
if (!server.getStatus().Equals(Constants.STATUS_FAILED))
{
server.onSecundaryServerFailure();
}
}
Thread.Sleep(TimeSpan.FromSeconds(Constants.PING_PERIOD));
}
}).Start();
System.Console.WriteLine("enter commands to control server:");
System.Console.WriteLine(" f to fail");
System.Console.WriteLine(" r to recover");
System.Console.WriteLine(" s to freeze");
while (true)
{
string command = System.Console.ReadLine();
if (command.Equals("f"))
{
server.fail();
}
else if (command.Equals("r"))
{
server.recover();
}
else if (command.Equals("s"))
{
server.freeze();
}
}
}