简体   繁体   English

lidgren / XNA如何使用DiscoverLocalPeers返回IP

[英]lidgren/XNA how to use DiscoverLocalPeers to return IPs

I want to create a server/client game in XNA 4.0 using lidgren where the client can list available servers/hosts and choose which server to join. 我想使用Lidgren在XNA 4.0中创建服务器/客户端游戏,客户端可以在其中列出可用的服务器/主机并选择要加入的服务器。

How can i use DiscoverLocalPeers or Client.DiscoverLocalPeers(40012); 我如何使用DiscoverLocalPeers或Client.DiscoverLocalPeers(40012); function to return a list of servers discovered. 函数返回发现的服务器列表。 I am assuming the function looks for available server using the same port but i would like to list available servers using the port incase there more than one server. 我假设函数使用相同的端口查找可用的服务器,但是如果有多个服务器,我想使用该端口列出可用的服务器。 Is it possible or is my understanding of the function wrong. 我可能对该功能理解不正确吗?

Your help would be greatly appreciated 您的帮助将不胜感激

I am not an expert with this library but DiscoverLocalPeers has a return type of void so I guess that this function only sends a message to servers with type DiscoveryRequest . 我不是该库的专家,但是DiscoverLocalPeers的返回类型为void因此我猜想此函数仅将消息发送到类型为DiscoveryRequest服务器。 So on your server side you should have something like this in order to handle incoming data : 因此,在服务器端,您应该具有以下类似内容,以便处理传入的数据:

 switch (incommingMessage.MessageType)
{
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.StatusChanged:
                    case NetIncomingMessageType.DiscoveryRequest :
                            // here, you should send a response back with type DiscoveryResponse

                    default:
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM