本文整理汇总了C#中Server.Server.getStatus方法的典型用法代码示例。如果您正苦于以下问题:C# Server.getStatus方法的具体用法?C# Server.getStatus怎么用?C# Server.getStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.getStatus方法的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();
}
}
}