WebSocket服务器可以与托管Web应用程序的Web服务器不同吗?

I am planning to implement or use a .NET solution for WebSocket Server for an industrial web HMI app I am creating, my web HMI app is hosted by Apache web server with PHP.

So is it possible that the webpage, hosted by Apache server (on port 81), to connect and open WebSockets to a Web Socket Server running (on its own on .NET platform) on a different port (say 82)?

My current way is that I am doing an AJAX polling using setInterval and at Apache server, cURL + PHP transfers the requests to a realtime data WCF service.

I actually want to have this WebSocket server talk to this realtime data WCF service, and have the browsers update on WebSockets.

.NET WebSocket server is not a requirement, if it's possible for a WebSocket server to be hosted in parallel to apache web server. If there is an Apache+PHP solution for a web socket server that can be hosted on same port or other port, I am okay.

In general, your life will be a lot easier down the road if your HTTP server and your WebSocket server use the same ports. You eliminate configuration hurdles, as well as firewall challenges (whereas either your HTTP server or your WebSocket server (or neither one of them) are using the standard port or ports: 80/443).

If the origin of your HTML page and your WebSocket server are different, you'll have to configure your system for cross-origin.

The origins are considered different, even if only the ports are different. See more details on the same origin policy.

As for the cross-origin configuration, you'll have to declare the following on your WebSocket server: go ahead and do serve requests coming from HTML pages that were loaded from my HTTP server (which has a different origin, that is different port in your case, than that of the WebSocket server).