jaffa
jaffa

Reputation: 27350

How do I specify a valid port when testing a client and server socket application?

I'm trying to connect a client to a server test program in C# using Sockets on my local machine. However, I get the "server actively refused the connection" error for every port number I try.

How do I pick a valid port number to be able to just test out sockets between a sample client and server? Is there a valid port no. I can use for this scenario?

Upvotes: 0

Views: 2682

Answers (1)

Nicholas Carey
Nicholas Carey

Reputation: 74197

The most likely reasons you might not be able to bind to your desired port on the server of your choice:

  • Your system has a firewall configured to prevent outbound connections on the port in question.
  • Your network imposes such a restriction, either via a firewall or proxy/gateway.

  • The server's network won't allow inbound connections on the port in question, either via firewall or proxy/gateway.

  • The server itself is firewalled and won't allow inbound connections on the port in question.

Finally, it's always possible that the daemon in question on the server isn't running.

Check your ports:

  • 0–1023 (0x000–0x03FF)
    are reserved for "well-known ports" and typically have certain restrictions, at least for the server end of things. It wouldn't make much sense to require special permissions for a client to use a well-known port.

  • 1024–65535 (0x0400–0xFFFF)
    are putatively open for anybody to use.

    However...every system has a range of ports designated as ephemeral ports that should not normally be used. Berkeley sockets used 1024–4999 as the emphemeral range, but that range varies from system to system and is [usually] configurable.

Upvotes: 1

Related Questions