5

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.

Is it possible to use Javascript to communicate with (i.e. transfer files/text) other devices on the local network? The IP addresses of the devices are already known and I'm looking for a peer-to-peer connection here.

Note: As this website is static, there is no server side code that can be controlled.

Thanks

Lumin
  • 373
  • 6
  • 21
  • can you be more specific? – Peter Aug 31 '19 at 18:12
  • @Peter what details do you need? – Lumin Aug 31 '19 at 18:15
  • your question is very broad and open-ended. browsers have many security mechanisms which limit what you can do with them and by providing us with more context about the problem you are targeting, we can better assist you. Don't post responses as a comment; edit your original post. – Peter Aug 31 '19 at 18:17
  • @Peter Thanks for replying quickly; So is it possible to do this in client side Javascript or will it have to be done with a external server? – Lumin Aug 31 '19 at 18:19
  • No, you cannot do this on the client side, you will need a backend for this. – goto Aug 31 '19 at 18:21
  • Other devices that loaded your static page (and run its js) as well? Other devices that could run some kind of server software? Something else? – Bergi Aug 31 '19 at 18:44

1 Answers1

1

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. 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. Some method of communicating the signalling between the clients must exist, and this is usually done via web sockets and an intermediary server.

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.

Embedded HTTP Server

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. Your static web page can use the Fetch API or AJAX to retrieve data from devices.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Can you elaborate on how one could go about adding an embedded HTTP Server to the Site? E.g. how can I make the computer listen for traffic on a specific port? – bcye Apr 18 '20 at 20:12
  • @Bruce I don't really know what to elaborate on without more information. You basically write some native application that runs on whatever device you want to have host that web server. If I were doing this on PCs and I wanted something I could deploy easily to multiple platforms, I'd probably make a little Node.js server. But, perhaps you have a skillset for something else... some C# or something. I wouldn't know. You could also deploy your native code via a browser extension... but not to some arbitrary device of course. – Brad Apr 18 '20 at 20:40
  • ah ok I though you meant that one can embed a server into a webpage. – bcye Apr 20 '20 at 08:33