Automatically forward ports from clients

1k views Asked by At

My system has a server and multiple clients. the server has a service for the clients and each client has a service too, for talking to other clients.

I forward the server's service port manually on the router but the future client can not do it by him self after the installation.

Is there a way to automatically forward ports by code from the client side through the installation?

My main question is - Does this approach is wise? Should the system needs to be build deferentially?

Project details:

  1. C# - WCF, Communication - NetTcpBinding.
  2. The server is on my computer (Home network). Server's service port : 8080.
  3. The clients can be installed everywhere. Client's service port: 8081.

*I'm not known with the IIS technology, can it help in this scenario?

1

There are 1 answers

4
Chavez On BEST ANSWER

The model you're describing sounds like a mesh network, generally you do not want clients to forward ports, be it automatically or not.

If it's absolutely necessary you could implement UPnP, there is an elaborate article here describing how to do so in .NET with a library. Note that you will have to select a different port.

I would strongly recommend to go for a different option though, having the server manage connections between clients is more managable and safer. There are very few valid arguments in favor of a model where a server is present and clients omit it at times:

  • Bandwidth, the server might not be able to handle all the data with reasonable throughput (i.e. torrent)
  • Security, the server might be only there for client updates (i.e. P2P chatclient with updater)

From the sound of it, your project does not apply to either.

EDIT: Because you have indicated the project is basically a torrent client, I would recommend reading up on the UPnP article.