We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

IIS c++ websocket related module developmentRSS

6 replies

Last post Jul 23, 2019 11:18 AM by svandex

  • IIS c++ websocket related module development

    Apr 17, 2019 01:22 PM|svandex|LINK

    I have followed steps from this link: https://blogs.iis.net/jennylaw/iis-and-websockets

    I got the IWebSocketContext pointer, but when i call ReadFragment/WriteFragment, the returned value HRESULT is E_NOTIMPL, which means the two functions are not implemented. I have loaded the WebSocket module on my site. 

    I also want to know which stage function of request processing pipeline I should write code to. I have written code in OnEndRequest function, and then E_NOTIMPL emerges. When I write code in OnExecuteRequestHandler, code wont stop in the break point I have set within the function. 

    I also want to know the inner mechanism of official websocket module, does the module add NamedModuleContext "websocket" to IHttpContext, or do I have to set up a IHttpStoreContext first, then websocket module rewrite the module to "websocket" NamedModuleContext, so that websocket communication can be established, and the two functions works?

    Could anyone give me an example to accomplish the websocket communication? 

  • Re: IIS c++ websocket related module development

    Apr 19, 2019 01:15 PM|svandex|LINK

    I solved the problem by myself :D

    I found that you can only use async version of the two functions. set fAsync flag to TRUE and with an AsyncCompletion function in another thread to do what you want next.

  • Re: IIS c++ websocket related module development

    Jun 24, 2019 04:34 PM|rflsouza|LINK

    Please, can you give some examples of how you did it?

  • Re: IIS c++ websocket related module development

    Jun 25, 2019 01:45 PM|svandex|LINK

    Check out my implementation here: https://github.com/svandex/rignet

    cpp file is here https://github.com/svandex/RigNet/blob/master/src/Svandex.cpp 

    and this implementation is running in my server right now, but still a bit issue in my repository, for more than 127 bytes websocket message would be concatenated, this is also mentioned by websocket standard. I dont know what happened in this websocket module implemented by Microsoft.

    If you are chinese, you can also check my blog post(https://blog.svandex.cn/2019/04/26/start-on-iis-cpp-development/) related to IIS module development, this blog post mentioned how to implement a websocket server in IIS Module. 

  • Re: IIS c++ websocket related module development

    Jul 02, 2019 09:02 PM|rflsouza|LINK

    @svandex, thank you very much for the return!

    Unfortunately I'm from Brazil, but I'm going to put in a translator to read the blog, it's very difficult to find material on IIS module development for C ++.

    I was able to do some implementations of standard HTTP request, file upload, content handling and so on. Now I was trying to implement the websocket, so I have some time I will try to go back to my test project and see your code. I had been able to send data and stopped receiving.

    Currently I have an application in ISAPI, so I can validate well I will migrate to use module :)


  • Re: IIS c++ websocket related module development

    Jul 23, 2019 11:06 AM|rflsouza|LINK

    Hi svandex

    I did not test your project, as I understand you looped to read, I tried to follow this logic, but it will be limited in the number of threads that IIS supports (Maximum Threads Count). PoolThreadLimit = max (256).

    I did a stress test program in win32, it connects and keeps sending messages to the server, the server responds with echo.

    Using the while (true) in the test fails to exceed 250 websocket clients, as provided by the IIS limitation. I found nothing to increase this number.

    So I changed not to use while (true) in reading, leaving everything asynchronous and IIS controlling client threads, managed to put 20,000 clients and in less than 1 hour to send and receive more than 5 million messages. Server CPU at 0% and memory less than 800mb.

    My server:
    Xeon L5520 (8 core - 16 logical) 2.27Ghz
    12 GB memory
    Windows 2016 - IIS 10

    If you are interested, then I will write on my blog and put the images of the test. let me know!

  • Re: IIS c++ websocket related module development

    Jul 23, 2019 11:18 AM|svandex|LINK

    so you set a large enough number as buffer length?

    I didn't test my server as my site is used for only several automobile test engineers.

    Looking forward to your blog.