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


C# NetPeer.Connect方法代码示例

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


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

示例1: DoInit

        private static void DoInit()
        {
            if (IsHost)
            {
                NetPeerConfiguration config = new NetPeerConfiguration("MonoPlatformerGame");
                config.Port = DataStorage.GetLocalPlayerConfig().ServerPort;
                config.MaximumConnections = 32;
                config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
                config.EnableUPnP = true;
                netPeer = new NetServer(config);
                netPeer.Start();
                netPeer.UPnP.ForwardPort(DataStorage.GetLocalPlayerConfig().ServerPort, "Server port");
                JapeLog.WriteLine("Server Started");
                Initialized = true;
            }
            else
            {
                NetPeerConfiguration config = new NetPeerConfiguration("MonoPlatformerGame");
                config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
                netPeer = new NetClient(config);

                NetOutgoingMessage hailMessage = CreateMessage();
                hailMessage.Write((int)DataType.Login);
                hailMessage.Write("Hello there");
                netPeer.Start();
                netPeer.Connect(DataStorage.GetLocalPlayerConfig().ServerIP, DataStorage.GetLocalPlayerConfig().ServerPort, hailMessage);
                Initialized = true;
            }
            //JapeLog.WriteLine("Connected to Server");
        }
开发者ID:Johanw123,项目名称:MonoPlatformerGame,代码行数:30,代码来源:NetManager.cs

示例2: ConnectToService

        /// <summary>
        /// Подключение к P2P сервису. Для создания UDP окна.
        /// </summary>
        /// <param name="remotePoint">Адрес сервиса.</param>
        internal void ConnectToService(IPEndPoint remotePoint)
        {
            ThrowIfDisposed();

              if (Interlocked.CompareExchange(ref state, (int)PeerState.ConnectedToService, (int)PeerState.NotConnected) != (int)PeerState.NotConnected)
            throw new InvalidOperationException("Peer has not right state.");

              if (handler != null && handler.Status == NetPeerStatus.Running)
            throw new ArgumentException("Already runned.");

              var config = new NetPeerConfiguration(NetConfigString);
              config.Port = 0;
              config.AcceptIncomingConnections = true;
              config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

              if (remotePoint.AddressFamily == AddressFamily.InterNetworkV6)
            config.LocalAddress = IPAddress.IPv6Any;

              handler = new NetPeer(config);
              syncContext.Send(p => ((NetPeer)p).RegisterReceivedCallback(ReceivedCallback), handler);
              handler.Start();

              var hailMessage = handler.CreateMessage();
              using (var client = ClientModel.Get())
              {
            var localPoint = new IPEndPoint(Connection.GetIPAddress(remotePoint.AddressFamily), handler.Port);

            hailMessage.Write(client.User.Nick);
            hailMessage.Write(localPoint);
              }

              serviceConnection = handler.Connect(remotePoint, hailMessage);

              ClientModel.Logger.WriteDebug("AsyncPeer.ConnectToService({0})", remotePoint);
        }
开发者ID:Nowsoud,项目名称:TCPChat,代码行数:39,代码来源:AsyncPeer.cs


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