本文整理汇总了C#中NetworkClient.Open方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkClient.Open方法的具体用法?C# NetworkClient.Open怎么用?C# NetworkClient.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkClient
的用法示例。
在下文中一共展示了NetworkClient.Open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainX
public static void MainX(string[] args)
{
ServiceHost service = new ServiceHost(NetworkInput.Instance);
ServiceEndpoint endpoint = service.AddServiceEndpoint(
typeof(XnaSpace.Input.INetworkInputService),
new NetTcpBinding(),
args[0]);
Console.WriteLine(endpoint.ListenUri);
service.Open();
Console.WriteLine("Create Another");
Console.ReadLine();
Binding binding = new NetTcpBinding();
EndpointAddress endpointAddress = new EndpointAddress(args[1]);
NetworkClient client = new NetworkClient(binding, endpointAddress);
client.Open();
using (Space game = new Space(client))
{
game.Run();
}
try
{
client.Close();
service.Close();
}
catch (Exception)
{
}
}
示例2: StartNetwork
void StartNetwork()
{
Config config = new Config();
ServiceHost service = new ServiceHost(NetworkInput.Instance);
service.AddServiceEndpoint(
typeof(XnaSpace.Input.INetworkInputService),
new NetTcpBinding(),
config.PlayerEndpoint);
service.Open();
Binding binding = new NetTcpBinding();
EndpointAddress endpointAddress = new EndpointAddress(config.EnemyEndpoint);
NetworkClient client = new NetworkClient(binding, endpointAddress);
int tries = 50;
while (0 != tries)
{
try
{
client.Open();
break;
}
catch (Exception)
{
Thread.Sleep(1000);
}
--tries;
}
using (Space game = new Space(client))
{
game.Run();
}
try
{
client.Close();
service.Close();
}
catch (Exception)
{
}
}