هل يمكنني فتح اتصال Websocket بخادم محلي يعمل على منفذ تعسفي؟

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

  •  14-11-2019
  •  | 
  •  

سؤال

لدي خادم محلي إخراج بيانات جهاز استشعار المنزل في الوقت الحقيقي، وأريد تصوره في متصفحي.

سؤالي، هل يمكنني استخدام Websocket لفتح الاتصال من متصفحي إلى الخادم المحلي؟كيف أذهب للقيام بذلك؟

يعمل الخادم المحلي على رقم منفذ معين 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