C# 如何获取打开的“TcpListeners”列表

发布于 2024-10-13 11:38:54 字数 143 浏览 0 评论 0原文

我想向我的一款游戏添加多人游戏支持,因此我创建了一个“创建服务器”按钮,用于打开 TcpListener 并侦听连接请求,以及一个“加入服务器”按钮,我希望此按钮显示所有打开的 TcpListener 的列表(这样用户就可以点击它们进行连接) c# 中是否有任何内置函数?

I want to add multiplayersupport to one of my games, so i created a "Create Server" button which opens a TcpListener and listens to connecting requests, and a "Join Server" button, I want this button to display a List of all open TcpListeners (so the user can click on them an connect)
are there any in-built functions for this in c#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余罪 2024-10-20 11:38:54

您想要网络(或整个互联网)上所有计算机上的所有侦听器的列表吗?那么答案是否定的,没有内置函数可以实现这一点。

在小型 LAN 上,您也许可以摆脱服务器广播其存在的情况。在互联网出现之前,游戏通常就是这样做的。

如今,它们通常连接到中央服务器,其中包含托管实际游戏的所有服务器的列表。

不管怎样,你都会有一些工作要做。

You want a list of all listeners, on all machines on the network (or the entire internet)? Then the answer is no, there's no built-in function for that.

On a small LAN, you might be able to get away with the servers broadcasting their presence. This is how games usually did it before the internet came along.

Nowadays, they usually connect to a central server, which has a list of all servers that are hosting the actual games.

Either way, you'll have some work to do.

我ぃ本無心為│何有愛 2024-10-20 11:38:54

不幸的是,IP 或 TCP 规范中提供了此功能。 IP 和 TCP 都不提供任何“服务定位器”类型的功能。

要实现此功能,您需要某种方式让运行服务器的玩家将其连接信息(IP 地址/端口号)广播给正在寻找游戏的其他玩家。传统上,这是通过拥有发布可用游戏信息的主机/协调服务器来完成的。

Unfortunately this functionality for this in the IP or TCP Spec. Neither IP nor TCP provide any "service locater" type of functionality.

To implement this functionality, you need some way for your players running the servers to broadcast their connection information (ip address / port number) to the other players looking for a game. This is traditionally done through having a host / co-ordination server that publishes the information for the available games.

南巷近海 2024-10-20 11:38:54

如果您限制在局域网内,您可以在游戏服务器正在侦听的端口上进行广播,并让它们回复某种注册消息。

为了防止它干扰游戏,您甚至可以将其分开,并拥有一个单独的注册服务,该服务侦听与您的游戏侦听的端口不同的端口。

If you're limiting to a local area network you could broadcast on the port your game servers are listening on and have them reply with some kind of registration message.

To keep it from interfering with the game you could even separate it and have a separate registration service that listens on a different port than your game listens on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文