Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 2633 times)
0 Members and 1 Guest are viewing this topic.
Offline MBrenaman

Junior Member




Javanaut


« 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 Member




Friendly fire isn't friendly!


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

email?

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

Senior Member


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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void execute(String php){
      Date d=new Date();
 try{
              // 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(
                        uc.getInputStream()
                  )
              );
                  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.

Regards

ME

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

Junior Member




Javanaut


« 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 Member


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: http://MachineB.com/applet/output.php
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

M.E.
--------
Offline MBrenaman

Junior Member




Javanaut


« 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 Member


Projects: 4


Java games rock!


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

Hi Mathew,

Must be the language thing. Sorry about that!

Okay.

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:
http://mywebhosting.com/~mathew/writelines.php?line=hello

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
<?php
$line=$_GET['line'];
$outputfile="chatlines.php";
copy("chatlines.php", "temp.php" );
$maxread=filesize("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);
    fwrite($fout,$data);
  }while ((ftell($fp) < $maxread));
fwrite($fout,"<?php\necho(\"".$line."<br>\");?>");
fclose($fp);
fclose($fout);
?>


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
ME

M.E.
--------
Offline MBrenaman

Junior Member




Javanaut


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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!