Here I explore some options of hosting a HttpListener-based process on port 80 alongside another process that binds to port 80. Sharing one tcp port among multiple processes on the same Windows machine can sometimes be possible with some limitations. It mostly depends whether programs are implemented on top of the http.sys driver or not.
About Http.sys implementors
I have a custom web server that uses HttpListener internally. HttpListener (same as IIS) calls the Microsoft HTTP Server API which is an interface for the kernel-mode device driver called HTTP protocol stack (HTTP.sys). Any application that runs on top of http.sys can be made to run alongside and work together with another http.sys app (eg. IIS) on the same listening port. In order to achieve that, urlprefixes must be properly configured.
In my case I needed both IIS and HttpListener to listen on port 80.
As long as urlprefixes do not clash, this is possible.
To show all HTTP.SYS currently registered prefixes, you can use the following command:
netsh http show servicestate | findstr /r "Server\ Session HTTP"
Sharing same port with IIS
By default IIS binds to url prefix “http://*:80/“ which is a weak wildcard so all host-specific bindings by HttpListener will take precedence over IIS. So setting HttpListener to listen on “http://app1.mydomain.com:80/“ will work fine. Binding IIS to “http://app2.mydomain.com:80/“ would also work fine.
Segregating HttpListener and a non-http.sys server on different interfaces
Let there be two IPs available (for example 18.104.22.168 and 22.214.171.124) and we want to have HttpListener listen on one and Apache on the other.
Limit HTTP Server API to one IP by doing: netsh http add iplisten 126.96.36.199
This will limit HTTP Server API and thus HttpListener to only listen on 188.8.131.52.
Make apache bind to 184.108.40.206.
Segregating IIS and HttpListener on different interfaces
To bind IIS and HttpListener each to its own IP (for example 220.127.116.11 and 18.104.22.168). Set HttpListener’s urlprefix to “http://22.214.171.124:80“. Set IIS IP binding to “126.96.36.199” which will by default internally translate to a urlprefix of “http://188.8.131.52:80“.