本文整理汇总了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");
}
示例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);
}