Networking Forums

Networking Forums > Computer Networking > Windows Networking > General question about use of ports when programming with sockets

Reply
Thread Tools Display Modes

General question about use of ports when programming with sockets

 
 
0to60
Guest
Posts: n/a

 
      09-30-2005, 08:26 PM
I have a question about socket programming in general.

Exactly what happens behind the scenes when I one socket connects to a
different socket in listen mode? Using the dotnet framework, I create a
socket, bind it to a port, put it in listen mode, and then n sockets can
connect to it. The code:

Socket newSocket = listeningSocket.Accept();

returns a socket. I can communicate on newSocket, and listeningSocket goes
back to listen mode. Is newSocket using the port that I bound
listeningSocket to? If 5 clients connect to listeningSocket, and you check
the remote endpoint on each of them, they will all point to
listeningSocket's IP address and the same port. The 5 resulting newSockets
local endpoint properties all show the same port that listeningSocket is
bound to. Can many sockets all use the same port?

If this is the case, how come when I try to manually bind a some other
socket to the port that listeningSocket is listening on, I get a "port in
use" error?

So what happens behind the scenes? Does the newSocket use the same port
that listeningSocket is bound to? Or does it newSocket get "assigned" a
free port by the WSA code wrapped by the Socket class? When I check
newSocket's local endpoint property, it says the same port that
listeningSocket is bound to. How can multiple sockets be using the same
port?


 
Reply With Quote
 
 
 
 
William Stacey [MVP]
Guest
Posts: n/a

 
      09-30-2005, 10:47 PM
Each socket must be unique by 4 values:
IP Local, Port Local
IP Remote, Port Remote

When the listener accepts a new socket, it fills (among other things) that
socket object with those four values. That means no other socket can use
those same values, at least one must be different. So the same client can
not connect to the same server and port using the same local IP and port.
Clients normally get dynamic ports so that allows a client to connect to the
same server/port more then once. On the listening side, when you try to
listen to the same IP and port more then once, you get an error unless you
allow duplicates which is another can of worms. HTH

--
William Stacey [MVP]

"0to60" <holeshot60_nospam_@yahoo.com> wrote in message
news:(E-Mail Removed)...
>I have a question about socket programming in general.
>
> Exactly what happens behind the scenes when I one socket connects to a
> different socket in listen mode? Using the dotnet framework, I create a
> socket, bind it to a port, put it in listen mode, and then n sockets can
> connect to it. The code:
>
> Socket newSocket = listeningSocket.Accept();
>
> returns a socket. I can communicate on newSocket, and listeningSocket
> goes
> back to listen mode. Is newSocket using the port that I bound
> listeningSocket to? If 5 clients connect to listeningSocket, and you
> check
> the remote endpoint on each of them, they will all point to
> listeningSocket's IP address and the same port. The 5 resulting
> newSockets
> local endpoint properties all show the same port that listeningSocket is
> bound to. Can many sockets all use the same port?
>
> If this is the case, how come when I try to manually bind a some other
> socket to the port that listeningSocket is listening on, I get a "port in
> use" error?
>
> So what happens behind the scenes? Does the newSocket use the same port
> that listeningSocket is bound to? Or does it newSocket get "assigned" a
> free port by the WSA code wrapped by the Socket class? When I check
> newSocket's local endpoint property, it says the same port that
> listeningSocket is bound to. How can multiple sockets be using the same
> port?
>
>



 
Reply With Quote
 
Arkady Frenkel
Guest
Posts: n/a

 
      10-09-2005, 03:34 PM
Additionally , as a server ( listen socket ) you can have 10 accepted
connections in XP ( look at
http://support.microsoft.com/default...b;en-us;314882 )
Arkady

"William Stacey [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Each socket must be unique by 4 values:
> IP Local, Port Local
> IP Remote, Port Remote
>
> When the listener accepts a new socket, it fills (among other things) that
> socket object with those four values. That means no other socket can use
> those same values, at least one must be different. So the same client can
> not connect to the same server and port using the same local IP and port.
> Clients normally get dynamic ports so that allows a client to connect to
> the same server/port more then once. On the listening side, when you try
> to listen to the same IP and port more then once, you get an error unless
> you allow duplicates which is another can of worms. HTH
>
> --
> William Stacey [MVP]
>
> "0to60" <holeshot60_nospam_@yahoo.com> wrote in message
> news:(E-Mail Removed)...
>>I have a question about socket programming in general.
>>
>> Exactly what happens behind the scenes when I one socket connects to a
>> different socket in listen mode? Using the dotnet framework, I create a
>> socket, bind it to a port, put it in listen mode, and then n sockets can
>> connect to it. The code:
>>
>> Socket newSocket = listeningSocket.Accept();
>>
>> returns a socket. I can communicate on newSocket, and listeningSocket
>> goes
>> back to listen mode. Is newSocket using the port that I bound
>> listeningSocket to? If 5 clients connect to listeningSocket, and you
>> check
>> the remote endpoint on each of them, they will all point to
>> listeningSocket's IP address and the same port. The 5 resulting
>> newSockets
>> local endpoint properties all show the same port that listeningSocket is
>> bound to. Can many sockets all use the same port?
>>
>> If this is the case, how come when I try to manually bind a some other
>> socket to the port that listeningSocket is listening on, I get a "port in
>> use" error?
>>
>> So what happens behind the scenes? Does the newSocket use the same port
>> that listeningSocket is bound to? Or does it newSocket get "assigned" a
>> free port by the WSA code wrapped by the Socket class? When I check
>> newSocket's local endpoint property, it says the same port that
>> listeningSocket is bound to. How can multiple sockets be using the same
>> port?
>>
>>

>
>



 
Reply With Quote
 
William Stacey [MVP]
Guest
Posts: n/a

 
      10-10-2005, 01:06 AM
I saw this little line at the end of that article:
"Per development: The connection limit refers to the number of
redirector-based connections and is enforced for any file, print, named
pipe, or mail slot session. The TCP connection limit is not enforced, but it
may be bound by legal agreement to not permit more than 10 clients. "

So from my read, this does not apply to sockets, but to redirector-based
connections. Is this true? Easy to test, but have not done so myself.

--
William Stacey [MVP]

"Arkady Frenkel" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Additionally , as a server ( listen socket ) you can have 10 accepted
> connections in XP ( look at
> http://support.microsoft.com/default...b;en-us;314882 )
> Arkady
>
> "William Stacey [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Each socket must be unique by 4 values:
>> IP Local, Port Local
>> IP Remote, Port Remote
>>
>> When the listener accepts a new socket, it fills (among other things)
>> that socket object with those four values. That means no other socket
>> can use those same values, at least one must be different. So the same
>> client can not connect to the same server and port using the same local
>> IP and port. Clients normally get dynamic ports so that allows a client
>> to connect to the same server/port more then once. On the listening
>> side, when you try to listen to the same IP and port more then once, you
>> get an error unless you allow duplicates which is another can of worms.
>> HTH
>>
>> --
>> William Stacey [MVP]
>>
>> "0to60" <holeshot60_nospam_@yahoo.com> wrote in message
>> news:(E-Mail Removed)...
>>>I have a question about socket programming in general.
>>>
>>> Exactly what happens behind the scenes when I one socket connects to a
>>> different socket in listen mode? Using the dotnet framework, I create a
>>> socket, bind it to a port, put it in listen mode, and then n sockets can
>>> connect to it. The code:
>>>
>>> Socket newSocket = listeningSocket.Accept();
>>>
>>> returns a socket. I can communicate on newSocket, and listeningSocket
>>> goes
>>> back to listen mode. Is newSocket using the port that I bound
>>> listeningSocket to? If 5 clients connect to listeningSocket, and you
>>> check
>>> the remote endpoint on each of them, they will all point to
>>> listeningSocket's IP address and the same port. The 5 resulting
>>> newSockets
>>> local endpoint properties all show the same port that listeningSocket is
>>> bound to. Can many sockets all use the same port?
>>>
>>> If this is the case, how come when I try to manually bind a some other
>>> socket to the port that listeningSocket is listening on, I get a "port
>>> in
>>> use" error?
>>>
>>> So what happens behind the scenes? Does the newSocket use the same port
>>> that listeningSocket is bound to? Or does it newSocket get "assigned" a
>>> free port by the WSA code wrapped by the Socket class? When I check
>>> newSocket's local endpoint property, it says the same port that
>>> listeningSocket is bound to. How can multiple sockets be using the same
>>> port?
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Arkady Frenkel
Guest
Posts: n/a

 
      10-10-2005, 09:59 AM
Due to the next ( that that KB )
"All logical drive, logical printer, and transport level connections
combined from a single computer are considered to be one session; therefore,
these connections only count as one connection in the ten- connection limit.
For example, if a user establishes two logical drive connections, two
Windows sockets, and one logical printer connection to a Windows XP system,
one session is established. As a result, there will be only one less
connection that can be made to the Windows XP system, even though three
logical connections have been established." that not only SMB connections
but winsock too , but I didn't check that too ( have to bother 11 buddies
for that )
Arkady


"William Stacey [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I saw this little line at the end of that article:
> "Per development: The connection limit refers to the number of
> redirector-based connections and is enforced for any file, print, named
> pipe, or mail slot session. The TCP connection limit is not enforced, but
> it may be bound by legal agreement to not permit more than 10 clients. "
>
> So from my read, this does not apply to sockets, but to redirector-based
> connections. Is this true? Easy to test, but have not done so myself.
>
> --
> William Stacey [MVP]
>
> "Arkady Frenkel" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Additionally , as a server ( listen socket ) you can have 10 accepted
>> connections in XP ( look at
>> http://support.microsoft.com/default...b;en-us;314882 )
>> Arkady
>>
>> "William Stacey [MVP]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Each socket must be unique by 4 values:
>>> IP Local, Port Local
>>> IP Remote, Port Remote
>>>
>>> When the listener accepts a new socket, it fills (among other things)
>>> that socket object with those four values. That means no other socket
>>> can use those same values, at least one must be different. So the same
>>> client can not connect to the same server and port using the same local
>>> IP and port. Clients normally get dynamic ports so that allows a client
>>> to connect to the same server/port more then once. On the listening
>>> side, when you try to listen to the same IP and port more then once, you
>>> get an error unless you allow duplicates which is another can of worms.
>>> HTH
>>>
>>> --
>>> William Stacey [MVP]
>>>
>>> "0to60" <holeshot60_nospam_@yahoo.com> wrote in message
>>> news:(E-Mail Removed)...
>>>>I have a question about socket programming in general.
>>>>
>>>> Exactly what happens behind the scenes when I one socket connects to a
>>>> different socket in listen mode? Using the dotnet framework, I create
>>>> a
>>>> socket, bind it to a port, put it in listen mode, and then n sockets
>>>> can
>>>> connect to it. The code:
>>>>
>>>> Socket newSocket = listeningSocket.Accept();
>>>>
>>>> returns a socket. I can communicate on newSocket, and listeningSocket
>>>> goes
>>>> back to listen mode. Is newSocket using the port that I bound
>>>> listeningSocket to? If 5 clients connect to listeningSocket, and you
>>>> check
>>>> the remote endpoint on each of them, they will all point to
>>>> listeningSocket's IP address and the same port. The 5 resulting
>>>> newSockets
>>>> local endpoint properties all show the same port that listeningSocket
>>>> is
>>>> bound to. Can many sockets all use the same port?
>>>>
>>>> If this is the case, how come when I try to manually bind a some other
>>>> socket to the port that listeningSocket is listening on, I get a "port
>>>> in
>>>> use" error?
>>>>
>>>> So what happens behind the scenes? Does the newSocket use the same
>>>> port
>>>> that listeningSocket is bound to? Or does it newSocket get "assigned"
>>>> a
>>>> free port by the WSA code wrapped by the Socket class? When I check
>>>> newSocket's local endpoint property, it says the same port that
>>>> listeningSocket is bound to. How can multiple sockets be using the
>>>> same
>>>> port?
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB Ports and Sockets gpl@fishcroft.ca Linux Networking 5 10-15-2005 11:17 PM
General VPN Question Dave Mc Windows Networking 3 09-07-2005 01:29 PM
General VPN question Dave Mc Windows Networking 1 08-05-2005 09:17 PM
Dell 2300 TrueMobile router question/ general wireless question Craig Wireless Internet 2 01-11-2004 06:26 PM
General 1M/Bit Question a1essex.com Broadband 9 09-30-2003 11:05 AM



1 2 3 4 5 6 7 8 9 10 11