开发者

C# how to get a list of open "TcpListeners"

开发者 https://www.devze.com 2023-02-06 05:45 出处:网络
I want to add multiplayersupport to one of my games, so i crea开发者_如何学JAVAted a \"Create Server\" button which opens a TcpListener and listens to connecting requests, and a \"Join Server\" button

I want to add multiplayersupport to one of my games, so i crea开发者_如何学JAVAted 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#?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消