简体   繁体   English

如何结合P2P和Web服务器方法?

[英]How to combine P2P and web-server approaches?

I would like to program a computer game which should be played by several participants. 我想编写一个应该由几个参与者玩的电脑游戏。 And I need to do it in two different ways. 我需要以两种不同的方式来做。 The first way is to program a web site where people can login and play. 第一种方法是对网站进行编程,使人们可以登录并玩游戏。 The second way is to have programs running locally and exchanging data with each other using P2P approach. 第二种方法是使程序在本地运行并使用P2P方法相互交换数据。

I know how to program both ways. 我知道如何双向编程。 In the first case I can use PHP. 在第一种情况下,我可以使用PHP。 In the second way I use Python or Java. 第二种方式,我使用Python或Java。 But in this case I need to do the same work twice (using different languages). 但是在这种情况下,我需要做两次相同的工作(使用不同的语言)。 And I want to avoid that (so, my question is how can I do it). 我想避免这种情况(因此,我的问题是我该怎么做)。

I almost solved my problem but in the end I have realized that it will not work this way. 我几乎解决了我的问题,但最终我意识到它无法以这种方式工作。 I wanted to use JavaScripts. 我想使用JavaScript。 I thought that with the JavaScript I can program an interface for the game which reads from and writes to a local file. 我以为可以使用JavaScript来为游戏编程一个接口,该接口可以读取和写入本地文件。 And then, in the case of the web server I upload and download the local file to the server. 然后,对于Web服务器,我将本地文件上传并下载到服务器。 And in the case of P2P approach I use Java or Python networking tools to exchange the local files between the user's computers. 对于P2P方法,我使用Java或Python网络工具在用户计算机之间交换本地文件。

But then I found out that JavaScript cannot read data from a web server. 但是后来我发现JavaScript无法从Web服务器读取数据。 So, my idea failed. 所以,我的想法失败了。 Does anybody have better ideas? 有人有更好的主意吗?

But then I found out that JavaScript cannot read data from a web server. 但是后来我发现JavaScript无法从Web服务器读取数据。

That's not true. 这不是真的。 You'll need to use AJAX to query the webserver from the Javascript page. 您需要使用AJAX从Javascript页面查询Web服务器。 If you're into Java, have a look into J2EE tutorials , and create your webapp using Java. 如果您喜欢Java,请阅读J2EE教程 ,并使用Java创建您的Web应用程序。 This way, you can still have a java base for all, and two different interfaces. 这样,您仍然可以为所有Java基础和两个不同的接口。

So my guess is that you want this computer game to be a single gameworld; 所以我的猜测是,您希望这款计算机游戏成为一个单一的游戏世界。 including both web-based clients and normal .exe participants. 包括基于Web的客户端和普通的.exe参与者。

Very understandable you only want to program 1 core. 非常容易理解,您只需要编程1个内核。 A standard solution from the P2P world is to use a daemon and integrate a light HTTP server in there. P2P世界的标准解决方案是使用守护程序,并在其中集成一个轻型HTTP服务器。 The browser can point to http://localhost:8821 and connect to the core that way. 浏览器可以指向http:// localhost:8821并以这种方式连接到核心。 Normal executable contains a GUI and core. 普通可执行文件包含一个GUI和核心。 So the core is probablt best done in Python or so. 因此,核心最好是用Python左右完成。 Then you can turn that into an executable; 然后,您可以将其转换为可执行文件。 plus in a .xpi browser installer. 加上.xpi浏览器安装程序。

Hope the brief architecture description above is understandable. 希望上面的简要架构描述是可以理解的。

-Johan. -Johan。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM