如何以最小的开销实现简单的无服务器p2p浏览器到浏览器消息传递?

时间:2022-05-27 08:08:48

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.

我正在尝试创建一些简单游戏的基本实现(tic tac toe为起始项目),可以在internet上玩,不需要*服务器。这个页面甚至不需要托管,可以在机器上本地运行,也可以托管在web服务器上。当主机托管游戏时,页面会通知主机的IP地址,然后可以通过任何方法(电话、即时消息等)发送给朋友。那个朋友将输入或复制/粘贴IP到一个连接对话框中,并且能够玩有问题的游戏。我希望这两方能够做到这一点,不需要安装任何额外的软件,也不需要联系任何类型的*服务器。

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.

我已经研究了许多涉及node的潜在解决方案。js、webrtc websockets,flash、java等。每一个与之相关的问题,例如要求*服务器,或者要求客户有可能需要下载的东西不是已经安装在他们的电脑上,或只传输音频和视频而不是被用于发送数据信息。告诉某人他们需要下载java可能显得微不足道。或者让我用flash开发应用程序,但这都与我的最终目标背道而驰。

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.

如果完全用javascript完成我要做的事情是不可能的,那么这就是不可能的。但是我不明白为什么不可以,因为浏览器可以独立地向url发送和接收文本数据,这些url解析为IPs或直接解析为IPs。其他的解决方案是受欢迎的,但是如果这是不可能的,那它真的应该是。

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

    应该使用完全免费的技术(如啤酒)。(没有flash,我意识到flash player的web应用程序可以免费编码,但层对层需要注册一个beta密钥,假设我可以免费获得,不一定永远免费)。

  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)

    没有外部服务器或错误对等点。(同样,在基于flash或unity的解决方案中,只要您使用它们的*服务器,对等点对对等点的模仿是可以实现的)

  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)

    没有客户端下载(当然,大多数人都安装了java或flash,但很多人都没有,而且java下载量很大,对不懂电脑的用户来说并不友好。它甚至现在尝试安装工具栏。除此之外,我的许多用户根本不愿意下载任何东西,包括java或unity。如前所述,它们都有与本项目相关的问题)

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?

总之,如果ajax可以向指定的IP发送请求并侦听响应。为什么我不能用纯js实现简单的对等消息传递呢?或者我可以吗?

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.

我不需要托管一个完整的web服务器或任何类型的分离应用程序或插件来发送和接收数据。

Am I missing something?

我遗漏了什么东西?

2 个解决方案

#1


12  

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.

在推荐了pubnub之后,我去了那里,并留下了一些印象。然而,我最终还是意外地发现了我一直在寻找的东西。RTCDataChannel就是答案。这个网站最终证明了我想要的是可能的。浏览器对这一功能的支持虽然不多,但却在不断增加,整个过程增强了我对浏览器社区中对等应用程序的支持不断增长的信心。

#2


0  

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?

总之,如果ajax可以向指定的IP发送请求并侦听响应。为什么我不能用纯js实现简单的对等消息传递呢?或者我可以吗?

It's due to the fact that an ajax request must be handled by an HTTP server so you still need to install a server to every clients.

这是因为ajax请求必须由HTTP服务器处理,所以仍然需要向每个客户端安装服务器。

say you want

说你想要的

  1. free
  2. 免费的
  3. no external servers
  4. 没有外部服务器
  5. no client downloads
  6. 没有客户端下载

I would say it is impossible to archive with all of these requirements except that you cut one of them off.

我想说的是,不可能对所有这些需求进行归档,除非你砍掉其中一个。

My suggestion is pubnub. This solution still need a server and it is not free(they have a free usage tier). But the good thing is you have an imitate p2p connection without doing server things and no client download needed.

我的建议是pubnub。这个解决方案仍然需要一个服务器,而且它不是免费的(它们有一个免费的使用层)。但是好的一面是你有一个模拟的p2p连接,不需要做服务器的事情,也不需要客户端下载。

#1


12  

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.

在推荐了pubnub之后,我去了那里,并留下了一些印象。然而,我最终还是意外地发现了我一直在寻找的东西。RTCDataChannel就是答案。这个网站最终证明了我想要的是可能的。浏览器对这一功能的支持虽然不多,但却在不断增加,整个过程增强了我对浏览器社区中对等应用程序的支持不断增长的信心。

#2


0  

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?

总之,如果ajax可以向指定的IP发送请求并侦听响应。为什么我不能用纯js实现简单的对等消息传递呢?或者我可以吗?

It's due to the fact that an ajax request must be handled by an HTTP server so you still need to install a server to every clients.

这是因为ajax请求必须由HTTP服务器处理,所以仍然需要向每个客户端安装服务器。

say you want

说你想要的

  1. free
  2. 免费的
  3. no external servers
  4. 没有外部服务器
  5. no client downloads
  6. 没有客户端下载

I would say it is impossible to archive with all of these requirements except that you cut one of them off.

我想说的是,不可能对所有这些需求进行归档,除非你砍掉其中一个。

My suggestion is pubnub. This solution still need a server and it is not free(they have a free usage tier). But the good thing is you have an imitate p2p connection without doing server things and no client download needed.

我的建议是pubnub。这个解决方案仍然需要一个服务器,而且它不是免费的(它们有一个免费的使用层)。但是好的一面是你有一个模拟的p2p连接,不需要做服务器的事情,也不需要客户端下载。