如何以最小的开销实现简单的无服务器p2p浏览器到浏览器消息传递? [英] How can I implement simple serverless p2p browser to browser messaging with minimal overhead?

查看:66
本文介绍了如何以最小的开销实现简单的无服务器p2p浏览器到浏览器消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些简单游戏的基本实现(井字游戏是一个开始的项目),可以在不需要中央服务器的情况下通过Internet进行游戏.该页面甚至不需要托管,可以在计算机上本地运行,也可以托管在Web服务器上.在托管游戏时,该页面将告知主机其IP地址,然后可以通过任何方法(电话,即时消息等)将其发送给朋友.那个朋友将把IP键入或复制/粘贴到加入对话框中,并能够玩有问题的游戏.我希望这两个参与方能够做到这一点,而无需安装任何其他软件,也无需联系任何类型的中央服务器.

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.

我研究了许多潜在的解决方案,涉及node.js,webrtc,websockets,flash,java等.每个解决方案都有一个相关的问题,例如需要中央服务器或要求客户端可能拥有下载他们的计算机上尚未安装的内容,或仅传输音频和视频并且对发送数据消息没有帮助的内容.告诉某人他们需要下载java ..或对我来说要使用Flash开发应用程序似乎微不足道,但这完全违背了我的最终目标.

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.

如果无法完全用javascript做我想做的事情,那就不可能了.但是我不明白为什么不能做到这一点,考虑到浏览器能够自行将文本数据发送和接收到解析为IP或直接解析为IP的URL.欢迎使用其他解决方案,但如果不可能做到这一点,那确实应该.

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. 应该使用完全免费的技术(例如在啤酒中).(没有闪存,我意识到可以免费编码Flash Player的Web应用程序,但是层中的点对点需要注册Beta键,前提是假设我可以免费获得,则不一定永远免费.)

  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.)

没有外部服务器或错误的对等.(同样在Flash或基于统一的解决方案中,只要您使用中央服务器,就可以实现对等的模仿)

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)

没有客户端下载(可以肯定的是,大多数人都安装了Java或Flash,但许多人没有安装,而且Java的下载量很大,对计算机不熟练的用户也不友好.它甚至尝试立即安装工具栏.在最重要的是,我的许多用户根本不愿意下载任何东西,包括java或unity.它们已经提到了与该项目有关的自己的问题)

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)

总之,如果ajax可以将请求发送到指定的IP并侦听响应..为什么我不能在纯js中获得简单的对等消息传递?或者可以吗?

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?

我不需要托管功能强大的Web服务器或单独的应用程序或任何形式的插件来发送和接收数据.

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.

我想念什么吗?

推荐答案

在推荐pubnub之后,我看了一下,并被部分印象深刻.但是,我最终偶然发现了我一直在寻找的难以置信"的东西.答案是RTCDataChannel.此站点最终表明,我想要的东西是可能的.浏览器对该功能的支持虽然很小,但仍在增长,整个过程使我更加坚定了对浏览器社区中对等应用程序支持的信任.

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.

这篇关于如何以最小的开销实现简单的无服务器p2p浏览器到浏览器消息传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆