Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Stable network ports #840

Closed
reinerh opened this issue Feb 19, 2024 · 3 comments
Closed

Feature request: Stable network ports #840

reinerh opened this issue Feb 19, 2024 · 3 comments
Labels

Comments

@reinerh
Copy link
Contributor

reinerh commented Feb 19, 2024

I was just playing cdogs-sdl with a friend over the Internet, which is quite fun!
It was a bit annoying that besides the main listening port (34219), it opens additional random ports that need to be reachable.
So to achieve a connection, I had to lookup the open ports and re-configure my router (firewall/NAT).

It would be nice if cdogs-sdl would choose the open ports from a predictable range (even better if only one port would be sufficient), so that the router needs to be configured only once.

@cxong
Copy link
Owner

cxong commented Feb 19, 2024

The solution C-Dogs SDL uses is described here https://cxong.github.io/2016/01/how-to-write-a-lan-server where the listen port 34219 is only used for server discovery, and the game connection itself is on a random free port. This is to avoid having that port conflict with some other program, and also allow multiple servers on the same machine

I don't know what's the canonical way of solving this, would you need to just add a firewall exception for cdogs-sdl?

@reinerh
Copy link
Contributor Author

reinerh commented Feb 19, 2024

Choosing random ports works fine on a LAN, where there are no firewall or other restrictions.
But for accepting connections from WAN/internet, the router (and a maybe firewall on the router) need to be configured to forward the ports to a machine inside the local network. Each time a different random port is chosen, the port needs to be figured out and the router needs to be re-configured with it.

A simple solution could be to pick random ports from a small but known range (e.g. 34220-34300). Such a fixed range can be easily configured in most routers.

Or maybe allow for configuration of the randomly chosen ports. Then the user can decide for themselves what ports to use.

would you need to just add a firewall exception for cdogs-sdl

On the machine itself it would be easy to allow every port of a program like cdogs-sdl, but the router (which is a different device) does not know the ports that cdogs-sdl is using, so it can't automatically forward them.
(There is UPnP for automated asking a router to forward ports to a machine, but using it is discouraged as it has a bunch of security problems.)

@cxong
Copy link
Owner

cxong commented Feb 22, 2024

I think it would be best to add a cmd line arg to specify the port to serve; since there is no standard way to specify a range for selecting a random port, we'd have to repeatedly bind() which could be very slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

2 participants