system assigned port with HttpListener?


G

Guest

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?
 
Ad

Advertisements

P

Peter Duniho

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
 
G

Guest

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.


Peter Duniho said:
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
 
Ad

Advertisements

R

Rick Strahl [MVP]

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 ---

--

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


Phil Bolduc said:
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.


Peter Duniho said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

HttpListener 0
Binding HttpListener to a free port 3
HttpListener 0
HttpListener with OpenSSL 1
HttpListener and SSL 0
HttpListener and Cookies 1
Profiling HttpListener app 5
comms port re-assignment 4

Top