IIS and Websockets
In IIS8 we introduced a new interface and associated API's to handle Websocket requests. IWebSocketContext.
Setup: To get this functionality working, Web Socket Protocol module should be enabled in the IIS features.
Runtime: If a incoming request is to be accepted as a Websocket request and subsequently upgraded, the handler must set the response status as 101. It should initiate a IHttpResponse->Flush, which will trigger the IIS Websocket module to do the necessary work to send out the 101 response to the client.
Once the response is sent, the handler can get a pointer to the IWebSocketContext through the IHttpContext3's GetNamedContext API.
The IWebSocketContext API exposes the necessary API's to read / write Websocket data.
Sample Code to get pointer to IWebSocketContext:
//
// Get Pointer to the IHttpContext3
//hr = HttpGetExtendedInterface( g_pServerInfo, pHttpContext, &pHttpContext3 );
if ( FAILED ( hr ) )
{
goto Finished;
}//
// Get Pointer to IWebSocketContext
//_pWebSocketContext = (IWebSocketContext *)pHttpContext3->GetNamedContextContainer()->GetNamedContext("websockets");
if ( _pWebSocketContext == NULL )
{
hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
goto Finished;
}
Reference
RFC http://www.rfc-editor.org/rfc/rfc6455.txt
IWebSocketContext:: http://msdn.microsoft.com/en-us/library/hh852804(v=vs.90).aspx
IHttpContext3: http://msdn.microsoft.com/en-us/library/hh852784(v=vs.90