1

Note: I've already read this question, its main answer and all the linked questions given there (more than 8 questions, such as this one but it talks about Flash, etc.). They are all ~ 2011, and things might have changed, thanks to new tech like WebRTC, etc.

Question:

If I give my IP to a friend, and he gives me his IP, can we send bytes to each other directly in the browser, with Javascript? (both users not in the same local network but connected via internet)

  1. If possible, without any 3rd party server. In this case we would both load a local HTML file containg the Javascript code allowing connection to each other. It seems possible to do such things with "chownat":

    allows clients behind NATs to communicate with a server behind a separate NAT with no port forwarding no DMZ setup, and no 3rd party involvement.

  2. If not possible without any server, then is it possible with a server involved just at the beginning of the process? (to make peers meet / know each other / to initiate the connection). Then once connection is established, the server would not be needed anymore: the 2 peers send bytes to each other, without server.

Is 1. or 2. possible nowadays with a standard browser (Firefox, Chrome, etc.) and without any router port configuration? With WebRTC for example?


Note: I've read about RTCDataChannel and tried this Simple_RTCDataChannel_sample but I don't see how two distant people can use this to connect to each other, this sample doesn't cover that. Here is the live demo. I don't see how it can be turned into a connection between two peers on internet.

Community
  • 1
  • 1
Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

0

If I give my IP to a friend, and he gives me his IP, can we send bytes to each other directly in the browser, with Javascript? [...] If possible, without any 3rd party server.

No, WebRTC uses session establishment tokens which cannot be reused, they must be generated anew for each connection. The IP address is not sufficient to establish a connection, at least such a token must also be generated and exchanged, either manually or...

If not possible without any server, then is it possible with a server involved just at the beginning of the process?

Yes, the server would act as rendezvous point to exchange tokens and optionally as STUN server.

Is 1. or 2. possible nowadays with a standard browser (Firefox, Chrome, etc.) and without any router port configuration?

That depends on your router(s), more specifically behind what types and how many layers of NAT each party is. But if they are well-behaved then the browsers will attempt NAT traversal with the help of a STUN server to establish a direct connection.

But generally browsers are less powerful when it comes to NAT traversal than native applications since native applications can talk to the firewall, UPnP/PMP/PCP routers and may also try NAT traversal techniques (e.g. TTL-based punching, linear port guessing) that are not part of the standard ICE/STUN approach.

the8472
  • 40,999
  • 5
  • 70
  • 122
  • Nice! Would you have a very basic code example of peer1 sending "hello world" from the browser and peer2 receiving it in the browser too? What Javascript technology would it use? RTC***? – Basj Jan 26 '18 at 23:40
  • Yes, WebRTC data channels. No code samples at hand, I'm mostly working from memory based on demos I have seen. – the8472 Jan 26 '18 at 23:46
  • search for rtc datachannel demo. there's some fairly simple ones out there. if there's any decent lib that makes it easier, it would be worth an answer mention or comment. – dandavis Jan 26 '18 at 23:47
  • @dandavis Yes I've seen this sample (and mentioned in the question): https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Simple_RTCDataChannel_sample and a github repo with it. But I tried, and I don't see how you connect to peers. This sample seems to be only running on a single computer, and doesn't offer anything to connect to another peer, or to enter the other peer's IP address. – Basj Jan 26 '18 at 23:52
  • @dandavis Here is the [live demo](http://mdn-samples.mozilla.org/s/webrtc-simple-datachannel/). I don't see how it can be turned into a connection between two peers on internet. – Basj Jan 26 '18 at 23:54
  • You asked whether it is possible. Googling for code samples or libraries is something different. – the8472 Jan 26 '18 at 23:58
  • i agreee, that demo sucks. https://rtcmulticonnection.herokuapp.com/demos/TextChat+FileSharing.html makes it simpler by breaking up the connection phase (using socket.io) and the high-level message passing phase – dandavis Jan 27 '18 at 00:02