임의의 포트에서 실행중인 로컬 서버에 WebSocket 연결을 열 수 있습니까?

StackOverflow https://stackoverflow.com/questions/6035292

  •  14-11-2019
  •  | 
  •  

문제

I 로컬 서버가 실시간 홈 센서 데이터를 출력하고 내 브라우저에서 시각화하고 싶습니다.

내 질문은 웹 소켓을 사용하여 브라우저에서 로컬 서버로의 연결을 열 수 있습니까?어떻게 할 것인가?

로컬 서버는 비 HTTP 지정 포트 번호에서 실행되며 변경할 수 없습니다.

도움이 되었습니까?

해결책

Yes and no.

No:

WebSockets are not raw TCP connections. They have an HTTP compatible handshake (for both security and compatibility with existing servers) and have some minimal framing for each packet to make WebSockets a message based protocol. Also, the current WebSocket API and protocol that exists in browsers as of today do not directly support binary data messages. They only UTF-8 encoded payloads.

Yes:

You can use websockify to proxy a WebSockets connection to a raw binary TCP server. websockify is a python proxy/bridge that has binary support and also includes a javascript library to make interacting with it easier. In addition, websockify includes the web-socket-js fallback/polyfill (implemented in Flash) for browser that do not have native WebSockets support. The downside is that you have to run websockify somewhere (either on the client system, the server system, or some other system). Also, websockify is Linux/UNIX only for now. On the plus side, websockify has a special mode that you can use to launch and wrap an existing service.

Disclaimer: I made websockify.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top