4
2
I have a few questions in regard to the following explanation of ports I found.
The Application layer talks to the Transport layer through a port. Ports are numbered and standard applications always use the same port.
The use of a port number allows the Transport protocol (typically TCP) to know which kind of contents is inside the packet, allowing it to know, at the reception side, to which Application protocol it should deliver the received data.
Why would a port number ever be used to tell what kind of application data protocol resides inside when there's not absolute guarantee?
To my understanding, there are no restrictions to what kind of application data you send over a port (it's just a suggestion). Plus isn't the protocol data already included somewhere in the packet for this purpose?
Also, What happens to the data if you send HTTP or some other kind of protocol to a destination of port 25 (which expects SMTP)?
Third, what happens to the data if you send it to a port that isn't bound with any program, and therefore not being listened to?
**Finally, if a port can only be bound to a single program, how can multiple programs that depend on incoming HTTP data be running on my computer at the same time?****
Thanks in advance!
Looking at the 2nd to last answer, does the router check the port numbers and send an error back if it's invalid? Looking at the 3rd to last answer, does the program requesting it take and handle the data, or the operating system? And to clarify your last answer, you can get around the limitation by creating a sub-port system with a server, and requesting connections from the server? Do servers add their own data to the stack before sending it, so incoming data can distinguished? – Griffin – 2012-01-22T02:52:40.327
The end system sends any error response; how could an intermediate router know what processes are running on the target system? – Daniel Pittman – 2012-01-22T02:56:36.123
The program, generally speaking. The OS is just a pipe, passing the data to whatever is listening on that port. (Generally speaking, in the sense that some platforms run servers in the kernel, which can blur the lines - but, essentially, still the application.) – Daniel Pittman – 2012-01-22T02:58:09.367
To your final question, the answer is "you are heading in the wrong direction"; the
accept
operation returns a new file handle for the TCP connection, which you treat like any other Unix file handle. The rest of it is just plain pipes moving data across the network. No sub-ports, on data added, nothing. Just plain packets with those four values identifying the connection. – Daniel Pittman – 2012-01-22T02:59:56.587Ok so a program request connection with another computer when it directs data to, say, port 80; Then that computer has a program that's listening to port 80 who's function is to transfer the connection it makes to one of the machines open ports. Is that right? How does the computer requesting connection get the new port number it's connected to? – Griffin – 2012-01-22T04:39:56.923
Found a very clear answer: http://stackoverflow.com/questions/3329641/how-do-multiple-clients-connect-simultaneously-to-one-port-say-80-on-a-server
– Griffin – 2012-01-22T06:06:51.647