|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
system assigned port with HttpListener?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? On Tue, 03 Apr 2007 23:44:01 -0700, Phil Bolduc
<PhilBol***@discussions.microsoft.com> wrote: > I want to be able to use an ephemeral port (system assigned port) with Does the port really have to be assigned by the system? Or is it > the HttpListener class but cannot figure out how to do 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 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. Show quote "Peter Duniho" wrote: > On Tue, 03 Apr 2007 23:44:01 -0700, Phil Bolduc > <PhilBol***@discussions.microsoft.com> wrote: > > > 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 > 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 --- Show quote "Phil Bolduc" <PhilBol***@discussions.microsoft.com> wrote in message news:ADCB5E31-D8D8-4EFF-B515-2FA21C27CB59@microsoft.com... > 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" wrote: > >> On Tue, 03 Apr 2007 23:44:01 -0700, Phil Bolduc >> <PhilBol***@discussions.microsoft.com> wrote: >> >> > 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 >> |
|||||||||||||||||||||||