Re: How does asp.net 2.0 allocate port numbers on localhost

Manoj Aggarwal <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.web
Organization Manoj Aggarwal
Message-ID <000301c70f7b$d46a9fa0$1201a8c0@manoj>
That was good Adam!!!

Doing little more research on ephemeral port range got me some more good
things to know, which I am sharing with others...
Below is the link from where I got the information. I have pasted some
information from the abstract in the mail only...

http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html


The Ephemeral Port Range
A TCP/IPv4 connection consists of two endpoints, and each endpoint consists
of an IP address and a port number.  Therefore, when a client user connects
to a server computer, an established connection can be thought of as the
4-tuple of (server IP, server port, client IP, client port).  Usually three
of the four are readily known -- client machine uses its own IP address and
when connecting to a remote service, the server machine's IP address and
service port number are required.

What is not immediately evident is that when a connection is established
that the client side of the connection uses a port number.  Unless a client
program explicitly requests a specific port number, the port number used is
an ephemeral port number.  Ephemeral ports are temporary ports assigned by a
machine's IP stack, and are assigned from a designated range of ports for
this purpose.  When the connection terminates, the ephemeral port is
available for reuse, although most IP stacks won't reuse that port number
until the entire pool of ephemeral ports have been used.  So, if the client
program reconnects, it will be assigned a different ephemeral port number
for its side of the new connection.

Similarly, for UDP/IP, when a datagram is sent by a client from an unbound
port number, an ephemeral port number is assigned automatically so the
receiving end can reply to the sender.



Microsoft Windows
Windows uses the traditional BSD range of 1024 through 4999 for its
ephemeral port range.  Unfortunately it appears that you can only set the
upper bound of the ephemeral port range.  Here is information excerpted from
Microsoft Knowledgebase Article 196271:

Start Registry Editor (Regedt32.exe).

Locate the following key in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

On the Edit menu, click Add Value, and then add the following registry
value:

Value Name: MaxUserPort Data Type: REG_DWORD Value: 65534 <for example>

Valid Range: 5000-65534 (decimal) Default: 0x1388 (5000 decimal)

Description: This parameter controls the maximum port number used when an
application requests any available user port from the system. Normally,
ephemeral (that is, short-lived) ports are allocated between the values of
1024 and 5000 inclusive.

Quit Registry Editor.
Note: There is another relevant KB article (812873) which claims to allow
you to set an exclusion range, which could mean that you could exclude ports
1024-9999 (for example) to have the ephemeral port range be 10000-65534.
However, we have not been able to get this to work (as of October 2004).


-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Adam Sills
Sent: Thursday, November 23, 2006 10:43 PM
To: [email protected]
Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers on
localhost

It's non-random port allocation from the ephemeral port range (1024-4999).
Windows takes care of this port allocation. You ask for one, and it gives
you the next available port. Visual Studio just does its best to reuse any
port it was previously given by Windows, to help avoid the need to update
web references, etc.

FYI, you can do the same manually through .NET code:

TcpListener listener = new TcpListener( 0 ); // specify port 0, or "give me
any port"

Adam..

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Paul van Brenk
Sent: Thursday, November 23, 2006 10:03 AM
To: [email protected]
Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers on
localhost

Probably... get random number, check for availability, repeat until you
have good one? I don't think there is an actual system involved.

Paul

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Manoj Aggarwal
Sent: Thursday, November 23, 2006 16:47
To: [email protected]
Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers on
localhost

Yes I can do that... but not sure enough if it works fine for me... Hope
it
helps. Also can someone please explain

How does port allocation mechanism work on asp.net
development webserver

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Ryan Heath
Sent: Thursday, November 23, 2006 04:37 PM
To: [email protected]
Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers on
localhost

Is it possible for you to change the property : use dynamic ports into
false?

HTH
// Ryan

On 11/23/06, Manoj Aggarwal <[email protected]> wrote:
> This property is disabled.......
>
> I am specifying my problem more elaborately
>
> Here is what am I doing?
>
> I am having 2 Projects in Solution explorer.
>
> Project 1 is a webservices project stored on the file system running
on
> asp.net development webserver with port allocated as 1480.
>
> Project 2 is a windows based application having the webreferences of
> webservices present in Project 1 like this
> http://localhost:1480/Server/HelloWorld.asmx
>
> Now the problem is that whenever asp.net allocates the port number
> dynamically to the websites running on development webserver.
>
> So what happens is whenever the localhost:1480 port changes to
> localhost:1907 or any other port number, I have to change all the
> webreferences present in Project 2. If there are 20 Webreferences then
I
> have to update 20 webreferences which is very tedious task. However I
can
> also update my app.config file with the new port number and make
application
> running. But the problem is that I won't be able to debug the
webservices.
>
> What I want is
>
> 1. I should be able to fix the port number of asp.net development
webserver
> for an particular website.
>
> 2. I want to know how does this port allocation mechanism work on
asp.net
> development webserver
>
> Thanks
> Manoj.
>
>
> -----Original Message-----
> From: Discussion of building .NET applications targeted for the Web
> [mailto:[email protected]] On Behalf Of Ryan Heath
> Sent: Thursday, November 23, 2006 03:44 PM
> To: [email protected]
> Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers
on
> localhost
>
> The properties window has the port options.
> Select your web project and if the properties window is not visible
> press CTRL+W, P
>
> HTH
> // Ryan
>
> On 11/23/06, Paul van Brenk <[email protected]> wrote:
> > If you use a web-application project you can assign which
port-number
> > the build in server should use...  Strange that this isn't an option
in
> > the default 'website project'...maybe it's hidden somewhere?
> >
> > Paul
> >
> > -----Original Message-----
> > From: Discussion of building .NET applications targeted for the Web
> > [mailto:[email protected]] On Behalf Of Manoj Aggarwal
> > Sent: Thursday, November 23, 2006 10:07
> > To: [email protected]
> > Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers
on
> > localhost
> >
> > I am using VS2005, But the problem with using IIS is that I have to
> > enable
> > remote debugging which is not very comfortable one. Having a website
on
> > the
> > file system allows me to debug more easily and fast. What I want to
know
> > is
> > that "I should be able to fix the port number for my website, so
that it
> > never keeps changing. Also I want to know how asp.net allocate the
port
> > number to the web server".
> >
> > Thanks,
> > Manoj Aggarwal.
> >
> > -----Original Message-----
> > From: Discussion of building .NET applications targeted for the Web
> > [mailto:[email protected]] On Behalf Of Efran Cobisi
> > Sent: Thursday, November 23, 2006 01:49 PM
> > To: [email protected]
> > Subject: Re: [DOTNET-WEB] How does asp.net 2.0 allocate port numbers
on
> > localhost
> >
> > Hi,
> >
> > Assuming you are using Visual Studio 2005, it could depends on the
fact
> > that, for file system Web sites, whenever you "start" a web site it
> > launches the ASP.NET Development server, which could change the port
it
> > binds to. I suggest you to configure your project as an IIS web site
and
> > set it as the "server" in the start options dialog box; it should
always
> > use the same - default - port.
> > See http://msdn2.microsoft.com/en-us/ms178730(vs.80).aspx for
additional
> > infos.
> >
> > HTH,
> >
> > Efran Cobisi
> >
> > Manoj Aggarwal wrote:
> > > Dear Friends,
> > >
> > >         I am working on a project based on Webservices and windows
> > forms.
> > My
> > > problem is that when I open the solution, sometimes the
webservices
> > starts
> > > on a different port number. For instance: earlier my webservices
> > application
> > > was running on localhost:1907 and next day I start it may run on
> > > localhost:1480. This becomes very problematic as I would have
given
> > the
> > > webreferences with port number 1907. And changing the port number
for
> > each
> > > and every webservice is a tedious task. Do any body have a
solution to
> > fix
> > > the localhost port number. Also I would like to know about how
asp.net
> > 2.0
> > > deals with port numbers.
> > >
> > > Thanks,
> > > Manoj Aggarwal.
> > >
> > > -----Original Message-----
> > > From: Discussion of building .NET applications targeted for the
Web
> > > [mailto:[email protected]] On Behalf Of Dean Cleaver
> > > Sent: Tuesday, November 14, 2006 03:07 AM
> > > To: [email protected]
> > > Subject: [DOTNET-WEB] And for another problem
> > >
> > > Completely different page this time (actually it's a UserControl,
not
> > a
> > > page) and it's taking about 1 minute to create each control to
design
> > > the page. It's been going for about 30 minutes now at 50%CPU
(hyper
> > > threaded, so that's all it can).
> > >
> > > Dino
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor.  http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> > >
> > > ===================================
> > > This list is hosted by DevelopMentorR  http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> > >
> >
> > ===================================
> > This list is hosted by DevelopMentorR  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> >
> > ===================================
> > This list is hosted by DevelopMentor(r)  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> >
> > ===================================
> > This list is hosted by DevelopMentor(r)  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> http://discuss.develop.com
> >
>
> ===================================
> This list is hosted by DevelopMentorR  http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.