Can I open a connection to a web server on a local server running on a random port?

I have a local server that displays my home data in real time, and I want to visualize it in my browser.

My question is: can I use websocket to open a connection from my browser to a local server? How can I do it?

The local server works with a port number other than http, and I cannot change it.

+6
source share
1 answer

Yes and no.

Not

WebSockets are not raw TCP connections. They have a handshake compatible with HTTP (both for security and compatibility with existing servers), and each package requires minimal framing to make WebSockets a message-based protocol. In addition, the current API and WebSocket protocol, which exists in browsers today, do not directly support binary data messages. They encode only UTF-8.

Yes

You can use websockify to proxy a WebSockets connection to a raw binary TCP server. websockify is a proxy / python bridge that has binary support and also includes a javascript library to make it easier to interact with. In addition, websockify includes web-socket-js fallback / polyfill (embedded in Flash) for a browser that does not have built-in WebSockets support. The downside is that you have to run websockify somewhere (either on the client system, and on the server system, or on some other system). In addition, websockify is Linux / UNIX just now. Websockify, on the other hand, has a special mode that you can use to start and migrate an existing service.

Disclaimer: I did websockify.

+7
source

Source: https://habr.com/ru/post/888350/


All Articles