简体   繁体   English

使用客户端 Javascript 与本地网络上的设备通信

[英]Communicate with devices on local network using client-side Javascript

I'm trying to build a website that allows you to transfer files to devices connected on your local network.我正在尝试建立一个网站,允许您将文件传输到本地网络上连接的设备。 This website is static, and will be hosted on GitHub pages.该网站是静态的,将托管在 GitHub 页面上。

Is it possible to use Javascript to communicate with (ie transfer files/text) other devices on the local network?是否可以使用 Javascript 与本地网络上的其他设备进行通信(即传输文件/文本)? The IP addresses of the devices are already known and I'm looking for a peer-to-peer connection here.设备的 IP 地址是已知的,我在这里寻找点对点连接。

Note: As this website is static, there is no server side code that can be controlled.注意:由于本网站是静态的,因此没有可以控制的服务器端代码。

Thanks谢谢

Yes, it's possible with caveats, depending on the specifics of your situation.是的,可能会有警告,具体取决于您的具体情况。

WebRTC实时时钟

With WebRTC, you can establish a real peer-to-peer connection between two clients on a network.使用 WebRTC,您可以在网络上的两个客户端之间建立真正的点对点连接。 They can send data (binary or strings), and media streams (like webcams and microphones).它们可以发送数据(二进制或字符串)和媒体流(如网络摄像头和麦克风)。 This can even work from a static page.这甚至可以从静态页面工作。

The catch is that you need some sort of server to help coordinate the connection.问题是您需要某种服务器来帮助协调连接。 Because of the way the WebRTC standard was originally set up, there is some back-and-forth that must occur to set up that peer-to-peer connection.由于 WebRTC 标准最初建立的方式,必须进行一些来回设置以建立对等连接。 Some method of communicating the signalling between the clients must exist, and this is usually done via web sockets and an intermediary server.必须存在某种在客户端之间传递信号的方法,这通常是通过 Web 套接字和中间服务器完成的。

There are some novel alternatives .有一些新颖的选择

In the future, ORTC may solve this issue, allowing a one-shot method for setting up the call, making the server-side requirements easier.未来, ORTC可能会解决这个问题,允许一次性建立呼叫的方法,使服务器端的需求更容易。

Embedded HTTP Server嵌入式 HTTP 服务器

You didn't elaborate on the specifics of what device you want to communicate with on your network, so maybe this is a possibility as well.您没有详细说明您想在网络上与之通信的设备的具体细节,所以也许这也是一种可能性。 There's nothing stopping your browser from communicating with devices on your LAN.没有什么可以阻止您的浏览器与 LAN 上的设备进行通信。 Your static web page can use the Fetch API or AJAX to retrieve data from devices.您的静态网页可以使用 Fetch API 或 AJAX 从设备检索数据。

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

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