Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (603)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (650)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Alternative to sockets??  (Read 2882 times)
0 Members and 1 Guest are viewing this topic.
Offline MBrenaman

Junior Devvie


« Posted 2004-05-21 23:36:14 »

Well, here's my problem. My web host doesn't support java and doesn't support custom php socket servers (this is only available for people who pay for a dedicated server  Sad ($50 a month) )

So my question is; Is there any alternative way to implement a simple multiplayer turn-based game. Could I go peer2peer (no not with applets)....

I could use php script to store in data file a player's name and move. And refresh and trim the data as I go.

Does this sound viable? Is there any other alternatives..
I'm very new to having my own webspace so I'm not sure if there are any alternatives.

-Mathew Brenaman
Offline Herkules

Senior Devvie

Friendly fire isn't friendly!

« Reply #1 - Posted 2004-05-22 10:38:34 »


HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline me

Senior Devvie

Projects: 4

Java games rock!

« Reply #2 - Posted 2004-05-23 07:10:29 »

Hello MBrenaman,

If your web hosting service allows mysql and php you might want to use this combination from your applet (or application) If speed isn't required during the turns you can call a php script from your code. Here is an example of how you might do this:

public void execute(String php){
      Date d=new Date();
              // Use time in order to avoid proxy-caching
                  URL Url = new URL(php+"&dummy="+d.getTime());
                  URLConnection uc = Url.openConnection();
                  BufferedReader in = new BufferedReader(
                      new InputStreamReader(
                  while ((inputLine = in.readLine()) != null){
                // Script is executing ..
                }catch(Exception e){System.out.println("Execute Error: "+e.toString());}

The String supplied must have the full path which in my case is a getCodeBase followed by the script name.
You can use the output of a script by handling it inside the loop.

Hope this helps.



Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MBrenaman

Junior Devvie


« Reply #3 - Posted 2004-05-23 11:56:23 »

See I was thinking of using PHP as the output mechanism for the applet and URLconnection for input (duh). And have the clients and php code do a servers job. Since I'm new to online/multiplayer gaming, do you think this is possible.

(I already wrote out a simple chat applet that works like this)

-Mathew Brenaman
Offline me

Senior Devvie

Projects: 4

Java games rock!

« Reply #4 - Posted 2004-05-24 10:38:30 »

Hi again,

You are getting me confused  Huh
Maybe it is a language issue since I'm not a native
english speaker/writer.

Is this what you want?

Gamer A accesses your homepage on the web hosts server.
Gamer B does this as well and you want communication
to take place between A and B after they have
connected to your server? If communication
starts between them you don't need the server anymore.

If this is what you are looking for you have to
forget about applets. Since applets can only access
resources on the server that has the applet.  
There is no way for you to connect the two computers
(A and B) using the applets running on their browsers.

If it is an Application you have written and you want
to tell Gamer A what the IP address of Gamer B is then at least
you need a way to store the IP address of the machines A and B
in order to communicate it to them.  You might use a php script
to read and write to a file. But this is dependent on
your provider. Not every webhosting company are allowing
these dangerous actions to take place.
MySQL is a database that is often available
for storing and communicating data.

Applets and PHP output:
The sentence " I was thinking of using PHP as the output
mechanism for the applet and URLconnection for input"
confused me. Since output of an Applet isn't send to the server.
A server has output that can be handle in a client.
My execute() method in the previous message could handle
the output of a PHP script.
Maybe you are trying to create a php script in an Applet and
want to send that to another computer?
If this is the case, I am sorry to tell you that Applets
are CLIENTS and cannot provide content for other Applets.
So in fact it would not be possible to do the following:
Browser on machine A:
You need to run a web server on Machine B to do such a thing
anyway. And your gamers propably don't have webservers running.
So applets can't talk to eachother. Java Applications on the
other hand can connect to systems that you know the IP address of.
See above section for that.

Applets and Servers:
Gamer A and Gamer B connect to web host and web host stores
the moves of the users. It will tell machines A and B what
the other gamer has done. This can be done using an Applet
since the client accesses resources on the same server as
the applet resides on.
Your Subject line refers to sockets and an alternative for them.
A Socket can be seen as a communication channel. Most (cheap)
Web Hosting servers aren't allowing you to run a process/java
to act as a server to communicate with sockets.
If you want to write a PHP script on the server that handles
files than in fact it can be used to do a chat programming with
two applets using the server as their postman. The MySQL
database would be of great help here since you don't have to
worry about security and ISP prevention.

Hope this helps a bit more!

Regards from ME

Offline MBrenaman

Junior Devvie


« Reply #5 - Posted 2004-05-24 10:58:37 »

Yes "me", you seem to have misunderstood me.

Applets can connect and read in files from thier originating server. They can not write though.

So I use php scripts to write to files. For example to store a highscore I connect to highscore.php?score=100.

Now how do you use this as a way to make simple multiplayer games.

I was thinking like having files on my server that stored who was online, messages, and game info. The client applets would sort everything.

-Mathew Brenaman
Offline me

Senior Devvie

Projects: 4

Java games rock!

« Reply #6 - Posted 2004-05-24 11:25:16 »

Hi Mathew,

Must be the language thing. Sorry about that!


So your webhosting company allows you to write files with php. That is a good thing.
The following is far from a nice solution but hopefully it
gets the point across:

let us assume the script is called writelines.php
and can be accessed in a browser using:

copy("chatlines.php", "temp.php" );
if (!($fout=fopen($outputfile,"w")))
        die ("Cannot create output file.");

if (!($fp=fopen("temp.php","r")))
        die ("Cannot open temporary file.");
do {
    $data = fgets($fp,$maxread);
  }while ((ftell($fp) < $maxread));

Basicly what it does is to create another php script
that you can access later to get the lines back.
I complete agree that this can be done far better and
you can use it to make your little database with the files. You mentioned php and therefore I created the
output completely in php

My message regarding the execute() method still can be applied to access these php scripts (writelines.php and chatlines.php).
Maybe you can make it into one php function that
returns some usefull coordinates which you can
read using the inputLine string in the method I provided
you with.

You propably won't get a great speed using http calls
but they should will work across proxies and stuff like that which UDP has a greater problem with.
And since you are looking for a turnbased game it propably will be fast enough.

Regards from

Offline MBrenaman

Junior Devvie


« Reply #7 - Posted 2004-05-24 13:36:02 »

Nice idea "me", thanks, and sorry for the confusion  Wink

-Mathew Brenaman
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (16 views)
2015-07-29 04:35:27

Riven (37 views)
2015-07-27 16:38:00

Riven (19 views)
2015-07-27 15:35:20

Riven (22 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (32 views)
2015-07-25 00:14:37

BurntPizza (42 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (31 views)
2015-07-22 22:16:53

NoxInc (20 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!