本文整理汇总了C#中Lidgren.Network.NetClient.DiscoverKnownPeer方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.DiscoverKnownPeer方法的具体用法?C# NetClient.DiscoverKnownPeer怎么用?C# NetClient.DiscoverKnownPeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.DiscoverKnownPeer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public override void Load()
{
bgContainer = new Sprite();
bgLayers = new Sprite[3];
AddChild(bgContainer);
for (int i = 0; i < 3; ++i)
{
bgLayers[i] = new Sprite();
var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
bmp2.X = bmp1.Width;
bgLayers[i].AddChild(bmp1);
bgLayers[i].AddChild(bmp2);
bgContainer.AddChild(bgLayers[i]);
}
// GUI
guiContainer = new Sprite();
AddChild(guiContainer);
NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network");
client = new NetClient(config);
client.Start();
client.DiscoverLocalPeers(14242);
client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT);
nick = NickGenerator.GenerateNick(client.UniqueIdentifier);
var screenNameLabel = new TextField();
screenNameLabel.font = Assets.GetFont("assets/MainFont");
screenNameLabel.text = "HOST GAME";
screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2;
screenNameLabel.Y = 10 / GameMain.mainScale;
guiContainer.AddChild(screenNameLabel);
var roomNameLabel = new TextField();
roomNameLabel.font = screenNameLabel.font;
roomNameLabel.text = "Room name: " + nick;
roomNameLabel.X = GameMain.ScreenWidth * 0.1f;
roomNameLabel.Y = GameMain.ScreenHeight / 2 - roomNameLabel.Height / 2;
roomNameLabel.ScaleX = roomNameLabel.ScaleY = 0.5f;
guiContainer.AddChild(roomNameLabel);
waitLabel = new TextField();
waitLabel.font = roomNameLabel.font;
waitLabel.text = "Waiting for other player to connect. . .";
waitLabel.X = roomNameLabel.X;
waitLabel.Y = roomNameLabel.Y + roomNameLabel.Height;
waitLabel.ScaleX = waitLabel.ScaleY = 0.25f;
guiContainer.AddChild(waitLabel);
}
示例2: checkButtons
bool checkButtons()
{
if (createButton.Triggered)
{
cleanup();
returnControl("create");
return true;
}
else if (joinLanButton.Triggered)
{
NetPeerConfiguration config = new NetPeerConfiguration("rts");
config.Port = 14243;
client = new NetClient(config);
client.Start();
//client.Configuration.SimulatedMinimumLatency = .5f;
//client.Configuration.SimulatedRandomLatency = .01f;
client.DiscoverLocalPeers(14242);
state = StartMenuState.Joining;
}
else if (joinIPButton.Triggered)
{
if (!File.Exists("C:\\rts hosts.txt"))
File.Create("C:\\rts hosts.txt");
string[] hosts = File.ReadAllLines("C:\\rts hosts.txt");
NetPeerConfiguration config = new NetPeerConfiguration("rts");
config.Port = 14243;
client = new NetClient(config);
client.Start();
//client.Configuration.SimulatedMinimumLatency = .5f;
//client.Configuration.SimulatedRandomLatency = .01f;
foreach (string host in hosts)
client.DiscoverKnownPeer(host, 14242);
state = StartMenuState.Joining;
}
else if (exitButton.Triggered)
{
cleanup();
returnControl("exit");
return true;
}
return false;
}
示例3: Load
public override void Load()
{
// Background
bgContainer = new Sprite();
bgLayers = new Sprite[3];
AddChild(bgContainer);
for (int i = 0; i < 3; ++i)
{
bgLayers[i] = new Sprite();
var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
bmp2.X = bmp1.Width;
bgLayers[i].AddChild(bmp1);
bgLayers[i].AddChild(bmp2);
bgContainer.AddChild(bgLayers[i]);
}
// GUI
guiContainer = new Sprite();
AddChild(guiContainer);
hosts = new List<HostLabel>();
font = Assets.GetFont("assets/MainFont");
var screenNameLabel = new TextField();
screenNameLabel.font = font;
screenNameLabel.text = "JOIN GAME";
screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2;
screenNameLabel.Y = 10 / GameMain.mainScale;
guiContainer.AddChild(screenNameLabel);
pointerLabel = new TextField();
pointerLabel.font = screenNameLabel.font;
pointerLabel.text = "Select a game to join";
pointerLabel.ScaleX = pointerLabel.ScaleY = 0.4f;
pointerLabel.X = GameMain.ScreenWidth / 2 - pointerLabel.Width / 2;
pointerLabel.Y = screenNameLabel.Y + screenNameLabel.Height;
guiContainer.AddChild(pointerLabel);
connectButton = new TextField();
connectButton.font = font;
connectButton.text = "Connect";
connectButton.ScaleX = connectButton.ScaleY = 0.5f;
connectButton.X = GameMain.ScreenWidth * 0.25f - connectButton.Width / 2;
connectButton.Y = GameMain.ScreenHeight - connectButton.Height;
connectButton.textColor = Color.DarkGray;
guiContainer.AddChild(connectButton);
refreshButton = new TextField();
refreshButton.font = font;
refreshButton.text = "Refresh";
refreshButton.ScaleX = refreshButton.ScaleY = 0.5f;
refreshButton.X = GameMain.ScreenWidth * 0.75f - refreshButton.Width / 2;
refreshButton.Y = connectButton.Y;
guiContainer.AddChild(refreshButton);
connectButton.AddEventListener(Event.TOUCH_END, onButtonDown);
refreshButton.AddEventListener(Event.TOUCH_END, onButtonDown);
NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network");
client = new NetClient(config);
client.Start();
nick = NickGenerator.GenerateNick((client.UniqueIdentifier));
client.DiscoverLocalPeers(14242);
client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT);
}
示例4: Connect
public void Connect()
{
if (netClient != null && netClient.Status == NetPeerStatus.Running)
return;
isConnected = false;
netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
// Create a client
netClient = new NetClient(netConfig);
netClient.Start();
try
{
if (waitForServer)
{
Thread connectionThread = new Thread(new ThreadStart(TryConnect));
connectionThread.Start();
}
else
{
if (isLocalAddress)
netClient.DiscoverLocalPeers(portNumber);
else
netClient.DiscoverKnownPeer(hostPoint);
}
}
catch (SocketException se)
{
Log.Write("Socket exception is thrown in Connect: " + se.StackTrace);
}
}
示例5: Load
public void Load()
{
isFinished = false;
// create client configuration
clientConfig = new NetPeerConfiguration("pacman");
//configure client
client = new NetClient(clientConfig);
//Start client
client.Start();
if (client != null)
{
NetIncomingMessage msg;
bool waitingForServer = true;
// Contact Server
client.DiscoverKnownPeer("localhost", 666);
//client.DiscoverLocalPeers(666);
while (waitingForServer)
{
while ((msg = client.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.DiscoveryResponse:
try
{
client.Connect(msg.SenderEndpoint);
//waitingForServer = false;
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
//waitingForServer = false;
}
break;
case NetIncomingMessageType.Data:
if (msg.ReadString() == "connected")
{
waitingForServer = false;
}
break;
}
}
if (timeoutCount > timeoutLimit)
{
waitingForServer = false;
}
double elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;
timeoutCount += elapsedTime;
}
}
foreach (GameScreen screen in gameScreens)
{
if (screen is ConfigMultiplayerScreen)
{
//((ConfigMultiplayerScreen)screen).setClient(client);
//((ConfigMultiplayerScreen)screen).setConntectedServer(client.ServerConnection.RemoteEndpoint.Address.ToString());
}
screenManager.AddScreen(screen, PlayerIndex.One);
}
isFinished = true;
}