Is this possible? Can we access the underlying socket, used by http.sys to serve a response for a given request. I want to be able to support full duplex communi开发者_JAVA百科cation over the http protocol on port 80.
Is there a way to grab the established socket for the current request, and keep it for full duplex communication?
My usage case are web sockets. The handshake of an web socket is actually a valid http request, and I would like to reuse my web server for upgrading it. Another port might not be opened on the client machine, so port 80 is vital.
Any alternatives are appreciated.
With http.sys you do not have access to the underlying socket. You can handle http requests and build the responses up out of fragments (from fragment cache, memory or files). If you need to have full control over the socket used (start as a http request, later upgrade it to a websocket socket after the "secret-websocket-handshake" is not supported.
What you can do is: use a rocket like full duplex system. Clients posts requests using HTTP 1.1 keep alive sockets and when the http.sys server receives those requests you can you can postpone the answer until the server to client triggered data is available or a time-out occurs. This is not as robust as a websocket but performs reasonably well and only adds one or two ms to the server reaction time (at least in my tests). The only problems arise when someone has multiple pages open in a browser to the server and the browser starts to let the pages share a single http request.. For this we kept the maximum polling as low as possible yielding substantially more web traffic.
The other option was to do the websocket ourselves in "socket-code" and the http requests using the "http.sys-code". This also works reasonably well but makes the code more complex.
精彩评论