Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was studying socket programming and certain questions came to my mind. These are some beginner level doubts

  1. Is it mandatory to to use well known port for a particular application. For example if i am using ssl, can i design a server to listen on 1000 rather than 443.

  2. For http we are connecting to port 80 from some other arbitrary port. Whys no port 80 to port 80 communcation.

  3. how a server responds to connections coming to it from different ports to its port 80.

  4. how many connections are possible to a particul

share|improve this question

closed as off topic by EightBitTony, Lucas Kauffman, growse, John Gardeniers, EEAA Jun 8 '12 at 12:29

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

You really haven't made any attempt to learn anything for yourself, have you? Without such kindergarten level knowledge you shouldn't even attempt to start programming anything that uses sockets. –  John Gardeniers Jun 8 '12 at 11:10
@JohnGardeniers I couldn't find answers yo my questions in Wikipedia or some other sites. My school also didn't help me. –  user71866 Jun 8 '12 at 15:51

2 Answers 2

up vote 3 down vote accepted
  1. No it is not mandatory, but some applications will expect that behavior by default (it makes the application more usable since you do not need to specify the port explicitly). For instance when you browse to website example.com you do not need to specify the port as the default one is 80. If you want to connect to a webserver on another port then you need to explicitly state that port. Sometimes people intentionally change ports, like the SSH port 22, to have less nuisance of the internet background noise.
  2. There is no reason why you would want that, suggest you are running a webserver on port 80 and want to surf to a website, you would be unable to do so as another service is using that port. As I said in 1, ports are just there so you do not need to specify them when you want to connect to a service, unless that service is being run on a not default port.
  3. That would depend on what is listening on its port 80, webservers will respond with the HTTP protocol. If for some reason you are running SSH on that port it will respond with SSH.
  4. There is however no limit on a specific port. There is a limit on the number of concurrent connections however, typically limited by the number of file descriptors the kernel supports (eg 2048). (stackoverflow)
share|improve this answer
you've got mail :) –  Lucas Kauffman Aug 2 '13 at 8:21

1 - This is just about "standards". By default, your browser will reach port 443 if you specify https, and 80 if http for exemple. You can do what ever you want for your particular use, but you will need to specify your custom port like this : some.place.to.go:1000 You may use the "reserved and well known" ports (0-1023) for the corresponding services, but if you need/want to use another, it's up to you... remember you have more than 65k of them :)

2- because ports < 1024 are reserved and cannot be used to initiate a connection

3- we are talking about TCP connections... On a particular machine, a port number coupled with the IP address of the machine is known as a socket. A combination of IP and port on both client and server is known as four tuple. This four tuple uniquely identifies a connection. So the server can talk with many clients because each client has made a unique connection to the server in order to talk to it.

Ex: A client (cli) connect to the server (srv) from a client port (5432) to the server port (80) cli:5432 -> srv:80

The server will respond to the client on the same client port : srv:80 -> cli:5432 And so on...

So for the 2) question : - imagine on the client's side that there is a http server running, the "local" port 80 is already used. - imagine there are several clients behind a router (with only 1 IP...), how couls many clients use the same originating port ?

If the connection was made from port 80 and not from an arbitrary port, neither of these situations will work. that's why we need to use an arbitrary port to initiate the request !

4- from an IP to the world, max 65535 (because you can only bind 65k sockets... as you have only 65k ports)

If you want to go further into this, I encourage you to read this stuff :

http://en.wikipedia.org/wiki/Internet_protocol_suite (and the related articles...)


share|improve this answer
4. Theoretically unlimited inbound connections (limited by kernel parameters) and a maximum of 65535 outbound connections. –  Dragos Jun 8 '12 at 9:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.