Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement simple serverless p2p browser to browser messaging with minimal overhead?

Tags:

I'm trying to create some basic implementations of simple games (tic tac toe is the starting project) which can be played over the internet without requiring a central server. The page would not even need to be hosted and could be run locally on the machine, or it could be hosted on a web server. When hosting the game, the page would inform the host of his IP address, which could then be sent by any method (phone, instant message, etc) to a friend. That friend would type or copy/paste the IP into a join dialog and be able to play the game in question. I would like these 2 parties to be able to do this without installing any additional software, and without contacting a central server of any kind.

I have looked into many potential solutions involving node.js, webrtc, websockets, flash, java, etc. Each one of these has a problem associated with it, such as requiring a central server, or requiring the client to potentially have to download something that isn't already installed on their computer, or only transferring audio and video and not being useful for sending data messages. It may seem trivial to tell someone that they need to download java.. or for me to develop the application with flash, but that is all contrary to my ultimate goals.

If it just isn't possible to do what I'm trying to do entirely in javascript, then it just isn't possible. But I don't see why it couldn't be, considering that browsers are capable on their own of sending and receiving text data to URLS which resolve to IPs or directly to IPs. Other solutions are welcome but if this isn't possible to do, it really should be.

The simple explanation of the exact requirements for what I'm trying to do is:

  1. Should use entirely free (as in beer) technologies. (no flash, i realize that web apps for flash player can be coded for free, but peer to peer in stratum requires a signup for a beta key, which assuming i could obtain for free, wouldn't necessarily remain free forever.)

  2. No external servers or false peer to peer. (again as in flash or unity based solutions where the imitation of peer to peer can be acheived, as long as you use their central server)

  3. No client downloads (sure, most people have java or flash installed, but many don't, and java is a pretty hefty download and not friendly for computer illiterate users. It even tries to install toolbars now. On top of this, many of my users would not be willing to download anything at all, including java or unity. Which have their own issues relating to this project as already mentioned)

In summary, if ajax can send a request to a specified IP and listen for a response.. why can't i get simple peer to peer messaging in pure js? Or can I?

I shouldn't need to host a full blown web server or a seperate application or plugin of any kind to send and receive data.

Am I missing something?

like image 287
Alex Brough Avatar asked Apr 15 '13 13:04

Alex Brough


1 Answers

After pubnub was recommended, I looked there and was partially impressed. However, I eventually stumbled across exactly what I was looking for UNBELIEVABLY. RTCDataChannel is the answer. This site finally showed that what I want is possible. The browser support for this functionality is small but growing and the entire ordeal has strengthened my faith in the growing support for peer to peer applications in the browser community.

like image 136
Alex Brough Avatar answered Nov 17 '22 02:11

Alex Brough