I can't really get my head around how websockets are configured and expected to work on the server.
In my case I have a machine (Windows 10) running IIS. On that machine I want to place my own websocket server application (WS-Server.exe), which should accept websocket connections from my client web app (WS-Client).
Doing all this on localhost
without IIS involved is pretty stragihtforward - simply make WS-Server.exe listen on some specific port, for example 5004
, and have WS-Client (the web app) connect to ws://127.0.0.1:5400
.
But now I want to deploy it and make it reachable over the Internet, and here's where I get lost. I understand that the Websocket handshake can be made via a normal HTTP call to IIS on port 80, and the connection will then be "upgraded" to a websocket connection by IIS if IIS is properly configured.
How do I properly configure IIS to enable websockets? I tried following the steps on Microsofts website to enable Websockets in IIS, but I'm not sure if that is all that is needed? When I try to connect to
127.0.0.1:80
from WS-Client I get an error message sayingError during WebSocket handshake: Unexpected response code: 200
. As I understand it, a websocket "HTTP upgrade" response should have response code101
? So it seems IIS is just serving a normal webpage instead?How do I tell IIS that I want all websocket connections to go to WS-Server.exe, which is running on the same machine? Do I need to tell IIS that I want
5004
to be used as the websocket port somehow? It seems like this step is always missing in all guides I've found, which I don't understand - what good is a websocket connection if you don't have something running on the server machine to actually send out data on it?
IWebSocketContext
- I have no idea what to do with? I have a Websocket server program written in Delphi - it's simply anexe
, and I need to somehow make it reachable from the internet using IIS (I guess?).