Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2007

Tip: Looking for answers? Try searching our database.

system assigned port with HttpListener?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Bolduc - 04 Apr 2007 07:44 GMT
I want to be able to use an ephemeral port (system assigned port) with the
HttpListener class but cannot figure out how to do it. With a TcpListener,
you would do something similar to:

   IPEndPoint localEP = new IPEndPoint(IPAddress.Any, 0);
   TcpListener tcpListener = new TcpListener(localEP);

I have a requirement to open up one or more http listeners so that external
components can connect. I would hate to have to write my own wrapper around
TcpListener. Plus I would like to be able to use http.sys.  Is this possible?
Peter Duniho - 04 Apr 2007 09:12 GMT
> I want to be able to use an ephemeral port (system assigned port) with  
> the HttpListener class but cannot figure out how to do it. [...]

Does the port really have to be assigned by the system?  Or is it  
sufficient to be able to specify a port that you've determined is unused?

According to the documentation, you can use the Prefixes property of  
HttpListener to specify (among other things) what port or ports to listen  
on.

http://msdn2.microsoft.com/en-us/library/system.net.httplistener.aspx

Pete
Phil Bolduc - 04 Apr 2007 17:18 GMT
First question would be, using code, how would I determine which port(s)
is/are free that am able to use. I am attempting to implement part of the
CCOW standard (http://www.hl7.org.au/CCOW.htm) which requires me to open one
or more listening ports.

By default on a windows system, the ephemeral port range is 1024 - 4999.
There is a registry setting that allows the upper range to be changed. I
really do not want have to assert registry read permissions on my assembly.

Well, I do not think it is possible to do what I am looking for using the
HttpListener. As the HTTP data transfered in this case is fairly limited, I
may have to handle reading and parsing the data myself using a TcpListener.

> > I want to be able to use an ephemeral port (system assigned port) with  
> > the HttpListener class but cannot figure out how to do it. [...]
[quoted text clipped - 9 lines]
>
> Pete
Rick Strahl [MVP] - 05 Apr 2007 03:58 GMT
Hi Phil,

If I remember right HTTPListener can use multiple listeners on a single port
as it passes off to http.sys which handles the actual scheduling of TCP/IP
connections.

If you really do need to find an open port there's an inelegant solution
that should work non-theless. You can try to open the port with TCP/IP and
see if it fails - if it fails it's most likely in use.

+++ Rick ---

Signature

Rick Strahl
West Wind Technologies
www.west-wind.com/weblog

> First question would be, using code, how would I determine which port(s)
> is/are free that am able to use. I am attempting to implement part of the
[quoted text clipped - 26 lines]
>>
>> Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.