Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket Server Behind IIS 7 Reverse Proxy

I've build a WebSocket chat server using the hybi-17 spec using .NET 4.0 and Sockets. If the browser connects to the chat server on port 81, everything functions as it should. However due to company firewalls etc. - I need to browser to connect to port 80 as this needs to be accessible to every PC in the world.

So I'm using IIS 7 as a reverse proxy. I have managed to get the browser to connect to ws://localhost/chatProxy on IIS 7 which then proxies the request to http://localhost:81/chatProxy where the websocket server is listening.

The Websocket server does the handshake and creates a socket for the connection, then goes back into a listening state.

The problem is, on the client side the websocket "onopen" events is never triggered. It's as if IIS doesn't send the request back to the browser.

Any help will be highly appreciated!!

Thanks in advance!!

like image 420
The_Butcher Avatar asked Nov 02 '11 15:11

The_Butcher


1 Answers

This is because IIS 7 does not know about websockets and is not able to proxy it. It will however forward the initial request to your websockets server as the initial request to a websocket server is a standard HTTP request (with some additional headers). IIS will know about that and simply forward the request. However, upon receiving the websocket request the websocket server will send a 101 response and switch into websocket mode. IIS will not understand the websocket traffic and will not be able to proxy that.

IIS 8 will natively support websockets (support will be included in .NET 4.5) and hopefully Microsoft will also add support to reverse proxy websocket traffic.

like image 180
Marco Miltenburg Avatar answered Sep 27 '22 19:09

Marco Miltenburg