简体   繁体   English

无法通过WebSocket连接Raspberry Pi服务器

[英]Can't connect Raspberry Pi server through WebSocket

There is a server running on a Raspberry Pi which, when authenticated by a String, sends me back Power Metering Info from Smart Plugs in my house every 30 seconds. Raspberry Pi上运行着一台服务器,当通过字符串进行身份验证时,每隔30秒就会从我家中的智能插头向我发送一次电能计量信息。 This Server opens a socket on port 50333. 该服务器在端口50333上打开一个套接字。

I can print the responses to the console in Eclipse with Java and Python by just connecting to it with a standard TCP Socket but when I try and use a websocket in javascript it just won't connect.... 我可以通过使用标准TCP套接字连接到Eclipse,使用Java和Python在Eclipse中打印对控制台的响应,但是当我尝试在javascript中使用websocket时,它将无法连接。

I have tried : 我努力了 :

var ws = new WebSocket("ws://l92.168.1.27:50333");

and: 和:

var tcpsock = new TCPSocket("192.168.1.27", "50333");

and it doesn't connect....I'm just wondering is my syntax right here or is there possibly some underlying factor that isn't explicitly evident? 而且它没有连接...。我只是想知道我的语法在这里,还是可能存在一些没有明确显示的潜在因素?

The WebSocket protocol is named a bit misleadingly. WebSocket协议的命名有点误导。 It is not a simple TCP socket for use in JS, but a more complex protocol based on Http involving a handshake and a package format. 它不是用于JS的简单TCP套接字,而是基于Http的更复杂的协议,涉及握手和包格式。 Your server will have to implement that protocol in order for you to be able to connect to it. 您的服务器将必须实现该协议,以便您能够连接到该协议。 The RFC is pretty useful: http://tools.ietf.org/html/rfc6455 RFC非常有用: http : //tools.ietf.org/html/rfc6455

It is not that hard to implement, but I bet there are a lot of libraries available that do this for you if you really need it. 实施起来并不难,但是我敢打赌,如果您确实需要它,那么有很多可用的库可以为您执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM