当前位置: 首页>>代码示例>>C#>>正文


C# NetPeerConfiguration.set_Port方法代码示例

本文整理汇总了C#中Lidgren.Network.NetPeerConfiguration.set_Port方法的典型用法代码示例。如果您正苦于以下问题:C# NetPeerConfiguration.set_Port方法的具体用法?C# NetPeerConfiguration.set_Port怎么用?C# NetPeerConfiguration.set_Port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lidgren.Network.NetPeerConfiguration的用法示例。


在下文中一共展示了NetPeerConfiguration.set_Port方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MGServer_DoWork

 private void MGServer_DoWork(object sender, DoWorkEventArgs e)
 {
   BackgroundWorker backgroundWorker = sender as BackgroundWorker;
   NetPeerConfiguration peerConfiguration = new NetPeerConfiguration(MonoGamerPeer.applicationIdentifier);
   peerConfiguration.EnableMessageType((NetIncomingMessageType) 32);
   peerConfiguration.EnableMessageType((NetIncomingMessageType) 64);
   peerConfiguration.EnableMessageType((NetIncomingMessageType) 2048);
   if (this.availableSession == null)
     peerConfiguration.set_Port(MonoGamerPeer.port);
   this.peer = new NetServer(peerConfiguration);
   ((NetPeer) this.peer).Start();
   this.myLocalAddress = MonoGamerPeer.GetMyLocalIpAddress();
   this.myLocalEndPoint = new IPEndPoint(IPAddress.Parse(this.myLocalAddress), MonoGamerPeer.port);
   while (this.session.LocalGamers.Count <= 0)
     Thread.Sleep(10);
   if (this.availableSession != null)
   {
     if (!this.online)
       ((NetPeer) this.peer).Connect(this.availableSession.EndPoint);
     else
       MonoGamerPeer.RequestNATIntroduction(this.availableSession.EndPoint, (NetPeer) this.peer);
   }
   else if (this.online)
   {
     IPAddress address = NetUtility.Resolve(MonoGamerPeer.masterServer);
     if (address == null)
       throw new Exception("Could not resolve live host");
     MonoGamerPeer.m_masterServer = new IPEndPoint(address, MonoGamerPeer.masterserverport);
     LocalNetworkGamer localNetworkGamer = this.session.LocalGamers[0];
     NetOutgoingMessage message = ((NetPeer) this.peer).CreateMessage();
     message.Write((byte) 0);
     message.Write(this.session.AllGamers.Count);
     message.Write(localNetworkGamer.Gamertag);
     message.Write(this.session.PrivateGamerSlots);
     message.Write(this.session.MaxGamers);
     message.Write(localNetworkGamer.IsHost);
     message.Write(this.myLocalEndPoint);
     message.Write(((NetPeer) this.peer).get_Configuration().get_AppIdentifier());
     int[] propertyData = new int[this.session.SessionProperties.Count * 2];
     NetworkSessionProperties.WriteProperties(this.session.SessionProperties, propertyData);
     for (int index = 0; index < propertyData.Length; ++index)
       message.Write(propertyData[index]);
     ((NetPeer) this.peer).SendUnconnectedMessage(message, MonoGamerPeer.m_masterServer);
   }
   do
   {
     NetIncomingMessage netIncomingMessage;
     while ((netIncomingMessage = ((NetPeer) this.peer).ReadMessage()) != null)
     {
       NetIncomingMessageType messageType = netIncomingMessage.get_MessageType();
       if (messageType <= 128)
       {
         if (messageType <= 8)
         {
           switch (messageType - 1)
           {
             case 0:
               NetConnectionStatus connectionStatus = (NetConnectionStatus) (int) netIncomingMessage.ReadByte();
               if (connectionStatus == 5)
                 this.session.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerLeft(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier())));
               if (connectionStatus == 3 && !this.pendingGamers.ContainsKey(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier()))
               {
                 this.pendingGamers.Add(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier(), netIncomingMessage.get_SenderConnection());
                 this.SendProfileRequest(netIncomingMessage.get_SenderConnection());
                 break;
               }
               else
                 break;
             case 1:
               break;
             default:
               if (messageType == 8)
               {
                 switch (netIncomingMessage.ReadByte())
                 {
                   case (byte) 0:
                     byte[] data = new byte[netIncomingMessage.get_LengthBytes() - 1];
                     netIncomingMessage.ReadBytes(data, 0, data.Length);
                     this.session.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandReceiveData(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier(), data)));
                     break;
                   case (byte) 3:
                     string endPoint1 = netIncomingMessage.ReadString();
                     try
                     {
                       IPEndPoint endPoint2 = MonoGamerPeer.ParseIPEndPoint(endPoint1);
                       if (this.myLocalEndPoint.ToString() != endPoint2.ToString() && !this.AlreadyConnected(endPoint2))
                       {
                         ((NetPeer) this.peer).Connect(endPoint2);
                         break;
                       }
                       else
                         break;
                     }
                     catch (Exception ex)
                     {
                       break;
                     }
                   case (byte) 4:
                     if (this.pendingGamers.ContainsKey(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier()))
                     {
//.........这里部分代码省略.........
开发者ID:Zeludon,项目名称:FEZ,代码行数:101,代码来源:MonoGamerPeer.cs


注:本文中的Lidgren.Network.NetPeerConfiguration.set_Port方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。