views:

180

answers:

2

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.

I know how to program both ways. In the first case I can use PHP. In the second way I use Python or 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. I thought that with the JavaScript I can program an interface for the game which reads from and writes to a local file. And then, in the case of the web server I upload and download the local file to the server. And in the case of P2P approach I use Java or Python networking tools to exchange the local files between the user's computers.

But then I found out that JavaScript cannot read data from a web server. So, my idea failed. Does anybody have better ideas?

A: 

But then I found out that JavaScript cannot read data from a web server.

That's not true. You'll need to use AJAX to query the webserver from the Javascript page. If you're into Java, have a look into J2EE tutorials, and create your webapp using Java. This way, you can still have a java base for all, and two different interfaces.

Valentin Rocher
Is J2EE a server side programming language?
Roman
It's the http server components of Java. See here for some tutorials : http://java.sun.com/javaee/reference/tutorials/
Valentin Rocher
A: 

So my guess is that you want this computer game to be a single gameworld; including both web-based clients and normal .exe participants.

Very understandable you only want to program 1 core. A standard solution from the P2P world is to use a daemon and integrate a light HTTP server in there. The browser can point to http://localhost:8821 and connect to the core that way. Normal executable contains a GUI and core. So the core is probablt best done in Python or so. Then you can turn that into an executable; plus in a .xpi browser installer.

Hope the brief architecture description above is understandable.

-Johan.