httpget and xampp?

Monkey Targets Forums/HTML5/httpget and xampp?

Midimaster(Posted 2012) [#1]
I'm doing some experiments with module Mnet and it seems to work on android with a far server and on html5, when I aks for files, wich are inside "/myapp.build/html5/" .

I have Xampp on my comuter, running apache and mysql. Now I want to get the file "C:\xampp\htdocs\myapp\index.php"

Normally with a browser I write "http:\\localhost\myapp\index.php" in the browsers adress line and the apache server sends back a startup-page.

So I tried with Mnet. I also tried "C:\...". But I cannot contact Xampp. It seems that Monkey's MServer catches all localhost inquiries. What can I do?

When I copy the index.php into the build directory to let the Mserver do the apache job, my game finds the file, but the MServer cannot react on php and only send the text of the php-file into the game


How do you simulate a apache server situation to test or develop monkey mnet communication in combination with php?


When I use the target "Android" and set the Mnet adress to...

"http://192.168.2.105/mygame/index.php"

...I get contact to my Xampp and MyGame displays the startup-page. But this string does also not work on Html5.


c.k.(Posted 2012) [#2]
You're probably running into some cross-domain protections built into the browser. What you might have to do is create a proxy php file stored in project.build/html5 that does the calls for you. This is how my Scoreoid module works. I send a request from my MonkeyGame.html file to the *local* php file, which then calls the remote php file for me.


DruggedBunny(Posted 2012) [#3]
I'm not sure how to get Apache to 'take over', but you can disable mserver in MonkeyPro\bin\config.*.txt:


'This is optional, OS default tool for .html files will be used if this not set.
'
HTML_PLAYER="${TRANSDIR}\mserver_winnt.exe"



You'll have to set HTML_PLAYER to 'something' in order to get the HTML5 target, but maybe this will be a start... ?


c.k.(Posted 2012) [#4]
In order to use Apache, you can just "build" instead of "build and run." Then, in your browser, go to localhost.

However, in Apache's config file, you need to make changes so Apache knows where to get your MonkeyGame.html file.


Midimaster(Posted 2012) [#5]
Thank you for showing me a way.

I did'nt know that "only build" would not start the MServer.

So, now I do it this way:

I have changed my code directory into a Xampp Subfolder:
C:\xampp\htdocs\Monkey


The serverside scripts are in a second folder ServerDir:
C:\xampp\htdocs\ServerDir\index.php


I'm writing my Monkey code and use the mnet command line
[monkeycode]result = ht.Get( "http://localhost/ServerDir", 3000 ) [/monkeycode]


and then Monkey build (without "run") it into...
C:\xampp\htdocs\Monkey\myapp.build\html5



When I now start the browser at ....


I get an answer from the Xampp. Even if the "server dir" is next to the Monkey Dir.

[Edit]
After some day, where it seems not to work anymore, I recognized, that it is important not to start the "MonkeyGame.html" by clicking it in the File System. You have to start it with entering the adress in the browser adress box starting with ....

With this it is possible to use MNet in a html5 target!

[Edit #2]
Now 2 weeks later I have no problems in using Xampp as a server for my android smartphone also during development. All I have to do is closing the MServer.


Rushino(Posted 2012) [#6]
I found a solution to make it work even with MServer open. I might post a tutorial if some are interested.


c.k.(Posted 2012) [#7]
I want to know how to do POST from Android! If ya got that, let me know...


Midimaster(Posted 2012) [#8]
from android it never was a problem.

I communicate with the MNet on my local network and also on a far server.

If the mobil is is part of the WLAN or connected by USB I can connect to the local Xampp host.

Adresses like "www.midimaster.com" are never a problem.

Here is a sample code:

[monkeycode]
Strict
Import mojo
Import mnet


Class TMyGame Extends App

Method OnCreate%()
SetUpdateRate 30
Simulator.Server = New Http()
.....
End

Method OnCreate%()
Local Result$=Simulator.Sende("G=123&P=1&N=990&A=C&X=0&Y=0&B=0")
....
End

End



Class Simulator

Global Server:Http = Null

Global SimLastCom$,Result$, VorResult$

Function Sende$(Anfrage$)
Local Adresse$,Result$
Adresse="http://192.168.2.105/MyGame/server.php?"
'Adresse="http://www.midimaster.de/MyGame/server.php5?"

'Print "Monkey sends: " + Anfrage
Result= Server.Get( Adresse + Anfrage, 3000 )
Return Result
End

[/monkeycode]


The server side is a minimal php5:
[monkeycode]
<?php

//** G E T E I N L E S E N ********************************************************
$game = $_GET["G"];
$player = $_GET["P"];
$aktion = $_GET["A"];
$nummer = $_GET["N"];
$punkte = $_GET["B"];
$x = $_GET["X"];
$y = $_GET["Y"];
if($aktion=="C"){
echo $Text;
}elseif($aktion=="R"){
......

}
Exit;

[/monkeycode]


in the native mnet.android.java I had to add one line to prevent not to get a crash on android, when there is no connection to the server:

[monkeycode] public String convertStreamToString( InputStream is )
{
// this is the newe line:
if (is == null) return "ERROR no Connection";
StringBuilder sb = new StringBuilder();
try
{
[/monkeycode]


c.k.(Posted 2012) [#9]
Midimaster, what about POST? Is that like

[monkeycode]
Result = Server.Post(...)
[/monkeycode]

?


Rushino(Posted 2012) [#10]
@midimaster : The reason it work its because its android.. this problem isn't affected on other platforms except HTML 5 because it use XmlHttpRequest.


Midimaster(Posted 2012) [#11]
Ah.. misunderstood you...

I did no GET or POST in my experiments, but only HTTP-GETs.

This means, I asked for a page on the server and GET it back as a string.

To send something to the server i use the adress options like POST/GET html forms do it:




Rushino(Posted 2012) [#12]
I doubt that i am wrong by saying that this link is actually a GET or Http GET .. its the same thing. Going to that URL is the same thing as doing an Http GETs. The browser actually do this request.

The POST is a bit different. It will include your values in the headers so you don't actually see them in the URL.


c.k.(Posted 2012) [#13]
Rushino, that is correct. The POST is definitely different, and used by some websites to process API requests. It HAS to be POST. Can't be GET.

So I've been waiting for a cross-platform module that has POST for all. Is that available yet?


Rushino(Posted 2012) [#14]
I am working on an HTML 5 one its near completion. What is strange is that its almost the same thing as a GET except you pass args..