本文整理汇总了C#中Lidgren.Network.NetClient.DiscoverLocalPeers方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.DiscoverLocalPeers方法的具体用法?C# NetClient.DiscoverLocalPeers怎么用?C# NetClient.DiscoverLocalPeers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.DiscoverLocalPeers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public void Connect()
{
client = new NetClient(config);
client.Start();
client.DiscoverLocalPeers(14242);
}
示例2: StartDiscoveryInternal
/// <summary>
///
/// </summary>
/// <param name="numPorts"></param>
/// <param name="timeout"></param>
void StartDiscoveryInternal ( int numPorts, TimeSpan timeout )
{
lock (lockObj) {
if (client!=null) {
Log.Warning("Discovery is already started.");
return;
}
this.timeout = timeout;
var netConfig = new NetPeerConfiguration( Game.GameID );
netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryRequest );
netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryResponse );
client = new NetClient( netConfig );
client.Start();
var svPort = Game.Network.Port;
var ports = Enumerable.Range(svPort, numPorts)
.Where( p => p <= ushort.MaxValue )
.ToArray();
Log.Message("Start discovery on ports: {0}", string.Join(", ", ports) );
foreach (var port in ports) {
client.DiscoverLocalPeers( port );
}
}
}
示例3: NetworkMultiplayer
public NetworkMultiplayer(bool createServer = false)
: base(GameModes.Network)
{
if(createServer)
GameServer = new GameServer();
//read network on each update
Game.Instance.OnUpdate += ReadNetwork;
//server config
NetPeerConfiguration config = new NetPeerConfiguration("tank");
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
//server creation
Client = new NetClient(config);
Client.Start();
if (!createServer)
{
//check whether the user has a known server
ListMenu serverMenu = new ListMenu("Do you want to connect to a given IP (if yes, enter in console)?", "tank.Code.YESORNOCHOOSENOW", ConnectionMethodSelectionCallback);
Scene.Add(serverMenu);
}
else//we know that a local server must exist
Client.DiscoverLocalPeers(14242);
//register handler for receiving data
OnClientData += IncomingHandler;
//are we client, or are we dancer?
if(!createServer)
Console.WriteLine("client");
}
示例4: ServerLayer
public ServerLayer()
{
NetPeerConfiguration config = new NetPeerConfiguration("xnaapp");
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.Start();
client.DiscoverLocalPeers(14242);
}
示例5: StartClient
private void StartClient(int port, string configName)
{
var config = new NetPeerConfiguration(configName);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
Client = new NetClient(config);
Client.Start();
Client.DiscoverLocalPeers(port);
}
示例6: 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);
}
示例7: NetworkCliente
public NetworkCliente(IWorld world, String serverName = "GameServer", int port = 14242, bool waitForConnect = true)
{
Debug.Assert(world != null);
this.world = world;
NetPeerConfiguration config = new NetPeerConfiguration(serverName);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.Start();
client.DiscoverLocalPeers(port);
if (waitForConnect)
{
waitConnection();
}
AddMessageHandler(NetMessageType.CreateNetworkObjectOnClient, RecieveCreateNetworkObjectOnClient);
AddMessageHandler(NetMessageType.PhysicInternalSync, StartRecieveSyncPhysicMessages);
AddMessageHandler(NetMessageType.Echo, HandleEchoMessage);
RegisterMessagePhysicSync(PhysicObjectTypes.SPHEREOBJECT,
(mes, obj) =>
{
IPhysicObject ent = obj.PhysicObject;
ent.Position = mes.ReadVector3();
ent.Rotation = Matrix.CreateFromQuaternion(mes.ReadRotation());
ent.Velocity = mes.ReadVector3();
ent.AngularVelocity = mes.ReadVector3();
}
);
RegisterMessagePhysicSync(PhysicObjectTypes.BOXOBJECT,
(mes, obj) =>
{
IPhysicObject ent = obj.PhysicObject;
ent.Position = mes.ReadVector3();
ent.Rotation = Matrix.CreateFromQuaternion(mes.ReadRotation());
ent.Velocity = mes.ReadVector3();
ent.AngularVelocity = mes.ReadVector3();
}
);
RegisterMessagePhysicSync(PhysicObjectTypes.CYLINDEROBJECT,
(mes, obj) =>
{
IPhysicObject ent = obj.PhysicObject;
ent.Position = mes.ReadVector3();
ent.Rotation = Matrix.CreateFromQuaternion(mes.ReadRotation());
ent.Velocity = mes.ReadVector3();
ent.AngularVelocity = mes.ReadVector3();
}
);
}
示例8: Start
public override void Start()
{
if (m_peer != null)
{
throw new InvalidOperationException("Client already running");
}
NetPeerConfiguration config = new NetPeerConfiguration(m_name);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
m_peer = new NetClient(config);
m_peer.Start();
m_peer.DiscoverLocalPeers(m_port);
}
示例9: ImageGetter
public ImageGetter(string host, NetPeerConfiguration copyConfig)
{
InitializeComponent();
NetPeerConfiguration config = copyConfig.Clone();
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
Client = new NetClient(config);
Client.Start();
if (!string.IsNullOrEmpty(host))
{
Client.Connect(host, 14242, GetApproveData());
}
else
{
Client.DiscoverLocalPeers(14242);
}
}
示例10: AutoDiscover
public static void AutoDiscover()
{
var config = new NetPeerConfiguration("spacebargame"); // New Lidgren config
Client = new NetClient(config); // Give NetClient Client our NetPeerConfig config
NetOutgoingMessage msg = Client.CreateMessage(); // msg is the outgoing message
Client.Start(); // Boot the client
Thread.Sleep(500); // Sleep 500
if (!NetworkingThread.IsAlive)
{
Thread NetworkingThread1 = new Thread(NetworkReceive);
NetworkingThread1.Start(); // Start NetworkingThread for incoming messages.
}
Thread.Sleep(500); // Sleep 500
Client.DiscoverLocalPeers(666);
}
示例11: 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;
}
示例12: 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);
}
示例13: 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);
}
}
示例14: SideScrollGame
public SideScrollGame(bool isNetworkGame, PlayerColor color, GameplayScreen gameplay)
{
main = this;
gameOver = false;
allPlayersDead = false;
allEnemiesDead = false;
this.gameplay = gameplay;
currentLevel = 1;
_goToNextLevel = false;
_isNetwork = isNetworkGame;
if (_isNetwork == false)
{
isHost = true;
if (color == PlayerColor.BLUE)
{
player = new Player(gameplay.content.Load<Texture2D>("Character/player"), new Vector2(10, 350));
}
Awake();
}
else
{
NetPeerConfiguration config = new NetPeerConfiguration("robotcontra");
string localIp = LocalIPAddress();
config.LocalAddress = IPAddress.Parse(localIp); // disable if there is firewall
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.Start();
client.DiscoverLocalPeers(16868);
Thread updateClientsWorld = new Thread(new ThreadStart(getPlayerUpdate));
updateClientsWorld.Start();
isFinishWriteLevel = false;
while (player == null)
{
//getting creating new player
}
NetworkAwake();
}
}
示例15: Connect
public void Connect(int port)
{
_netClient = new NetClient(_configuration);
_netClient.RegisterReceivedCallback(HandleMessages);
_netClient.Start();
_netClient.DiscoverLocalPeers(port);
}