|
-
April 15th, 2010, 09:24 PM
#1
A question of thorey
Iv'e been reading some tutorials on winsock programming and everything I read says that you only need to bind to a port as a server but not as a client.
Now the understanding I have is that a socket runs out of a port on one machine and into a port on another, sorta like water traveling thru pipes (sockets being the water)
And the question that I dont get is why dosn't a tcp client need to bind to a port to get to another port?
(Oh by the way this is my first post so hi everyone )
-
April 16th, 2010, 07:02 AM
#2
Re: A question of thorey
A server binds to a specific port because that is the port that the outside world knows and uses to connect to the server (21 for ftp e. g.).
A client need not bind to a specific port because it makes an outgoing connection to the server's well-known port. The local port is insignificant, so it can be left to the transport layer/OS to choose any arbitrary port.
Exception: some protocols like the rsh require that the client establishes a connection from a local port in a specific range. In that case, the client must bind to a port as well.
HTH,
Richard
-
April 16th, 2010, 09:29 AM
#3
Re: A question of thorey
[QUTOTE]
"The local port is insignificant, so it can be left to the transport layer/OS to choose any arbitrary port."[/QUTOTE]
So the client DOES have a port but it's all done automaticly behind close doors? if so does the client Port Always Match the number of the server port??
say for example a client is connecting to a server that is listening on port 2050 will the client also HAVE to connect to port 2050 to match it or can it just use any avaliable open port??
-
April 16th, 2010, 09:34 AM
#4
Re: A question of thorey
Where's an edit button when you need one LOL!
-
April 16th, 2010, 10:05 AM
#5
Re: A question of thorey
 Originally Posted by Matty_alan
[QUTOTE]
"The local port is insignificant, so it can be left to the transport layer/OS to choose any arbitrary port."[/QUTOTE]
So the client DOES have a port but it's all done automaticly behind close doors? if so does the client Port Always Match the number of the server port??
say for example a client is connecting to a server that is listening on port 2050 will the client also HAVE to connect to port 2050 to match it or can it just use any avaliable open port??
No, or clients couldn't connect on the localhost. That would make testing pretty tough. Ports are usually assigned arbitrarily by the stack (excluding ports in use) when a client connects.
-
April 17th, 2010, 11:58 AM
#6
Re: A question of thorey
 Originally Posted by Matty_alan
Iv'e been reading some tutorials on winsock programming and everything I read says that you only need to bind to a port as a server but not as a client.
Now the understanding I have is that a socket runs out of a port on one machine and into a port on another, sorta like water traveling thru pipes (sockets being the water)
And the question that I dont get is why dosn't a tcp client need to bind to a port to get to another port?
(Oh by the way this is my first post so hi everyone  )
Check this FAQ entry
Is it a bad idea to bind() to a particular port in a client program?
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
-
April 17th, 2010, 01:37 PM
#7
Re: A question of thorey
 Originally Posted by Matty_alan
...if so does the client Port Always Match the number of the server port?? say for example a client is connecting to a server that is listening on port 2050 will the client also HAVE to connect to port 2050 to match it or can it just use any avaliable open port??
As others have correctly indicated, no, the client typically will bind to some arbitrarily-numbered port. In Windows, these ports are opened starting at number 1025. You can see this for yourself if you open several browser windows to several different web servers, and then quickly (in a command prompt) type "netstat -an". This will give you a list of open sockets on your machine.
As a suggested research topic, look into "ephemeral ports", which is what these client ports are called.
Mike
-
May 3rd, 2010, 06:52 AM
#8
Re: A question of thorey
nameeste india,i am tariq from pakistani held kashmir so called(azad kashmir)i am one of thousands kashmiris who want to live and die with india.
Fat Burning Furnace
Force Factor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|