本文整理汇总了C#中Lidgren.Network.NetPeer.DiscoverLocalPeers方法的典型用法代码示例。如果您正苦于以下问题:C# NetPeer.DiscoverLocalPeers方法的具体用法?C# NetPeer.DiscoverLocalPeers怎么用?C# NetPeer.DiscoverLocalPeers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetPeer
的用法示例。
在下文中一共展示了NetPeer.DiscoverLocalPeers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMCL
public static void SendMCL()
{
Console.WriteLine("Enter Port: ");
int port = int.Parse(Console.ReadLine());
NetPeerConfiguration config = new NetPeerConfiguration("InduZtry");
config.Port = port;
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
config.EnableMessageType(NetIncomingMessageType.Data);
config.AcceptIncomingConnections = true;
//config.EnableUPnP = true;
peer = new NetPeer(config);
peer.Start();
//Console.WriteLine("UPnP IP: " + peer.UPnP.GetExternalIP());
Thread t = new Thread(RecvMCL);
t.IsBackground = true;
t.Start();
//Console.WriteLine("Enter Server IP: ");
//string sip = Console.ReadLine();
Console.WriteLine("Enter Server Port: ");
port = int.Parse(Console.ReadLine());
//peer.DiscoverKnownPeer(sip, port);
peer.DiscoverLocalPeers(port);
//while(true) {
//Thread.Sleep(10);
//Console.WriteLine("Port: ");
//int rport = int.Parse(Console.ReadLine());
//peer.DiscoverLocalPeers(rport);
//}
}
示例2: Find
internal static void Find (NetworkSessionType sessionType)
{
NetPeerConfiguration config = new NetPeerConfiguration (applicationIdentifier);
if (sessionType == NetworkSessionType.PlayerMatch) {
config.EnableMessageType (NetIncomingMessageType.UnconnectedData);
config.EnableMessageType (NetIncomingMessageType.NatIntroductionSuccess);
} else {
config.EnableMessageType (NetIncomingMessageType.DiscoveryRequest);
}
if (MonoGameNetworkConfiguration.Broadcast != IPAddress.None)
{
config.BroadcastAddress = MonoGameNetworkConfiguration.Broadcast;
}
netPeer = new NetPeer (config);
netPeer.Start ();
if (sessionType == NetworkSessionType.PlayerMatch) {
GetServerList (netPeer);
} else {
netPeer.DiscoverLocalPeers (port);
}
DateTime now = DateTime.Now;
discoveryMsgs = new List<NetIncomingMessage> ();
do {
NetIncomingMessage msg;
while ((msg = netPeer.ReadMessage ()) != null) {
switch (msg.MessageType) {
case NetIncomingMessageType.DiscoveryResponse:
discoveryMsgs.Add (msg);
break;
case NetIncomingMessageType.UnconnectedData:
if (msg.SenderEndpoint.Equals (m_masterServer)) {
discoveryMsgs.Add (msg);
/*
* // it's from the master server - must be a host
IPEndPoint hostInternal = msg.ReadIPEndpoint();
IPEndPoint hostExternal = msg.ReadIPEndpoint();
m_hostList.Add(new IPEndPoint[] { hostInternal, hostExternal });
*/
}
break;
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
//
// Just print diagnostic messages to console
//
#if DEBUG
Console.WriteLine ("Find: " + msg.ReadString ());
#endif
break;
}
}
} while ((DateTime.Now - now).Seconds <= 2);
netPeer.Shutdown ("Find shutting down");
}
示例3: PentagoNetwork
public PentagoNetwork(string playerName)
{
lastPingTime = DateTime.Now;
nextPingTime = lastPingTime.AddSeconds(1);
availablePeers = new List<peerType>();
config = new NetPeerConfiguration("Pentago");
// Enable DiscoveryResponse messages
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
config.EnableMessageType(NetIncomingMessageType.Data);
config.ConnectionTimeout = 5;
config.AcceptIncomingConnections = true;
config.MaximumConnections = 32;
config.Port = PORT_NUMBER;
peer = new NetPeer(config);
try
{
peer.Start();
peerOn = true;
Console.WriteLine("Peer Started");
Thread t = new Thread(waitForMessages);
t.SetApartmentState(ApartmentState.STA);
peerName = playerName;
t.Start();
Console.WriteLine(peerName);
peer.DiscoverLocalPeers(PORT_NUMBER);
}
catch(Exception ex)
{
Console.WriteLine("Caught exception: " + ex.Data);
}
}