简体   繁体   English

如何检查通过Kryonet LAN搜索连接的特定服务器?

[英]How to check for specific servers to connect to through Kryonet LAN search?

I'm making a game using Slick2D for game-logic and Kryonet for networking. 我正在使用Slick2D开发游戏逻辑,并使用Kryonet开发网络游戏。 The game can be played in 2-player multiplayer through LAN, where one player is the host-server and the other player is a client that receives information on what to render. 可以通过LAN在2人多人游戏中玩游戏,其中一个人是主机服务器,另一个人是客户端,负责接收有关渲染内容的信息。

When setting up the host, the first player enters a name for the server and then the second player (client) should search for servers over LAN on that specific port. 设置主机时,第一个播放器输入服务器的名称,然后第二个播放器(客户端)应在该特定端口上通过LAN搜索服务器。 My problem is that I am only aware of Kryonet's host discovery built-in method 我的问题是我只知道Kryonet的主机发现内置方法

InetAddress address = client.discoverHost(54777, 5000);

Which will find the first server running over LAN on the specified port. 它将找到在指定端口上通过LAN运行的第一台服务器。 However, once I check this server and send a packet confirming the name, if it doesn't match, how can I find another server without finding the same server that I just checked? 但是,一旦我检查了该服务器并发送了一个确认名称的数据包,如果不匹配,如何找到另一个服务器而不找到刚才检查的同一服务器?

Nevermind! 没关系! Just looked more closely at the Kryonet library and saw that discoverHosts() has another method that returns a list of InetAddresses. 只是更仔细地查看了Kryonet库,发现了DiscoverHosts()还有另一个返回InetAddresses列表的方法。 I think I can just go through the addresses, send packets confirming the name, and when I hit a correct server, keep that connection. 我想我可以浏览地址,发送确认名称的数据包,然后当我命中正确的服务器时保持该连接。

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

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