Write XML file from Android to PC over WiFi connection

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Thu Feb 23, 2017 5:01 am

Follow this instruction, to upload File via FTP Zilla
http://lessons.livecode.com/m/4071/l/69 ... -using-ftp

I have succesed to create FTP client with livecode
Then I test it from local host in PC (Windows 7) and it works
Then I test it from another PC (windos7) in the Network and it's works

But when I test on Andoid
IT'S STILL NO LUCK

here is the code

Code: Select all

on mouseUp
   put field ip_fld into tIP
   put field user_fld into tUser
   put field password_fld into tPassword
   # Start by getting the file to upload
   local tFileForUpload, tFileName
   answer file "Select a file to upload"
   put it into tFileForUpload
   # Get the name of the file for upload
   set the itemdel to "/"
   put the last item of tFileForUpload into tFileName
   put empty into field status_fld
   # Connect the start the upload
   local tDestination
   put "ftp://" & tUser & ":" & tPassword & "@" & tIP&"/" & tFileName into tDestination
   //put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "localhost/" & tFileName into tDestination
   libURLSetStatusCallback "uploadProgress", the long ID of me
   libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
end mouseUp
on uploadComplete pURL, pStatus
put "Status Update:" && pStatus &&  return after field status_fld
end uploadComplete
on uploadProgress pURL, pStatus
put "Status Update:" && pStatus &&  return before field status_fld
end uploadProgress
Anyone knows what wrong with my code?
Gilar | from INDONESIA

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Write XML file from Android to PC over WiFi connection

Post by SparkOut » Thu Feb 23, 2017 7:42 am

There is no libURL for Android so the lesson is only for desktop computers.

It looks like you will need to do this by POSTing the file to your xampp webserver which will handle the upload and saving to the required location.

There is a comprehensive example somewhere in the forum here. I will try and find it later when in front of my computer.

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Fri Feb 24, 2017 4:43 am

SparkOut wrote:There is no libURL for Android so the lesson is only for desktop computers.

It looks like you will need to do this by POSTing the file to your xampp webserver which will handle the upload and saving to the required location.

There is a comprehensive example somewhere in the forum here. I will try and find it later when in front of my computer.
Hi SparkOut ... thanks for keeping me on the track ...
So now do I have to Install Livecode Server and CGI?

Now I'm trying follow the instruction on this thread
and I'll try install Livecode Server and CGI first.
http://forums.livecode.com/phpBB2/viewt ... 15&t=27158
http://forums.livecode.com/viewtopic.ph ... 1d2#p96775
Gilar | from INDONESIA

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Write XML file from Android to PC over WiFi connection

Post by FourthWorld » Fri Feb 24, 2017 5:25 am

If your router is preventing you from sending data to your PC, it doesn't matter whether the HTTP requests are handled by mchttp or Apache.

Conversely, if you can use Apache you can probably use mchttp much more easily (fewer parts, simpler setup suitable for simpler tasks).

Is your router blocking your requests to Apache?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Fri Feb 24, 2017 7:10 am

FourthWorld wrote:If your router is preventing you from sending data to your PC, it doesn't matter whether the HTTP requests are handled by mchttp or Apache.
Conversely, if you can use Apache you can probably use mchttp much more easily (fewer parts, simpler setup suitable for simpler tasks).
Hi FourthWorld .... thank you for giving me another option to solve this problem.
Let me googling first about "mchttp" (I'm really newbie for programming)
FourthWorld wrote: Is your router blocking your requests to Apache?
I'm not sure about this.
But I have succesed to build Andorid apps which able to send command over socket connetion to a Server in PC.
I use CasparCG Server (www.casparcg.com) for doing this.
Can I tell you, if I have done with that, my router not bolocking requests Apache.

Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Write XML file from Android to PC over WiFi connection

Post by FourthWorld » Fri Feb 24, 2017 11:40 am

No need to look elsewhere for info on mchttpd - Alejandro included some background info and links several posts back in this thread. It's just a simple HTTP server, but since it's written in LiveCode it's much simpler to work with than Apache, NginX, Lightly, or other full-featured web servers.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Sat Feb 25, 2017 6:20 am

Now I start to make livecode Server and CGI
I follow this tutorial
http://lessons.livecode.com/m/4070/l/36 ... ith-apache
I put livecode-server folder in ==> C:\xampp\cgi-bin

I'm using XAMPP and Apche server.
here my "httpd.conf" file code

Code: Select all

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

    AddHandler livecode-script .lc

    Action livecode-script /xampp/cgi-bin/livecode-server.exe

</Directory>

<Directory "C:/xampp/cgi-bin/">

    Options ExecCGI

    Order allow,deny

    Allow from all
</Directory>
When I try to running Apache Server with XAMPP
here the log on XAMPP

Code: Select all

11:42:35 AM  [main] 	Starting Check-Timer
11:42:35 AM  [main] 	Control Panel Ready
11:42:45 AM  [Apache] 	Attempting to start Apache service...
11:42:46 AM  [Apache] 	Status change detected: running
12:05:38 PM  [Apache] 	Attempting to stop Apache service...
12:05:41 PM  [Apache] 	Status change detected: stopped
12:05:42 PM  [Apache] 	Attempting to start Apache service...
12:05:43 PM  [Apache] 	Status change detected: running
Then I want to test with 'test.lc" file
Here ... i don't how to create this file?

then I try to create it on notepad
here the result on web browser http://localhost/test.lc

Code: Select all

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.15 
I asume if the "test.lc" that i was created is wrong
then i search this file on forum search, and I got "upload.lc" file here
http://forums.livecode.com/viewtopic.ph ... background
Then i test on browser http://localhost/upload.lc
and I got the same result

Does anyone know whats wrong with my code?



Comment and help would be appreciated

Best Regard



Gilar Kadarsah
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Sat Feb 25, 2017 6:54 pm

Finally
- I Install Apache Server 2.4
- Install LiveCode Community Server 9

before that, I have to repair
- C++ Redistributable Visual Studio 2015
- Universal C Runtime update KB2999226.msu

Now I can running Livecode Server .... (i'm so happy) :)
Then I download a file from here (for Upload file to Livecode Server)
http://forums.livecode.com/phpBB2/viewt ... 15&t=27158
It use POST command to upload file to LiveCode Server

Deploy on stand Alone on Stand alone
- Tray on Local host the Result is ... Apps can sending file to livecode server.
- Try in Android Apps the Result is ... STILL NO LUCK.

Here some question I wanto Ask:
1. How to write path file on Android? It seems different with Windows.
I can not write file to a SpecialFolderPath on Android.
here is my code:

Code: Select all

.
.
.

   put the xml of card STAT into tXMLFinal
   put textencode(tXMLFinal,"UTF8") into url ("binfile:" & specialFolderPath("Documents")& slash & "Statistic.xml")
end mouseUp
This code works fine in Windows but It does not work on Android

2. I try Answer to get file Path but It's not Work. What should I write if I wan to handle command like this on Android
Here is the code

Code: Select all

on mouseUp
    answer file "what to upload?"
    put it into fld "fldPath"
end mouseUp
This code works fine in Windows but It does not work on Android
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Mon Feb 27, 2017 12:47 am

I think this is the problem,
I read this thread "Simple 'POST' of a file to LC Server" http://forums.livecode.com/phpBB2/viewt ... 15&t=27158
Maybe this is only for iOS (not for Android)
I read again "How To - LiveCode Mobile Tasks" http://lessons.livecode.com/m/4069/c/16396
SparkOut wrote:There is no libURL for Android so the lesson is only for desktop computers.
It looks like you will need to do this by POSTing the file to your xampp webserver which will handle the upload and saving to the required location.
There is a comprehensive example somewhere in the forum here. I will try and find it later when in front of my computer.
You are right.
Sorry I forgot about this.

Now ... I try to find out How to write XML file directly into Livecode Server without libURL
Is it possible to do this in LiveCode?

Image
Gilar | from INDONESIA

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Write XML file from Android to PC over WiFi connection

Post by FourthWorld » Mon Feb 27, 2017 2:50 am

GET and POST are supported in Android. In fact, in recent versions we even have socket support so you can write your own protocols as well, but for your needs the build-in support for HTTP/HTTPS should be fine.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android apps to a PC over WiFi conne

Post by gilar » Mon Feb 27, 2017 4:44 am

Hi ... Richard
Thanks for Keep posting on my thread.

Now i read again what capellan wrote, and open the link
and I look out about mchttd.mc, I have downloaded it. open the package (mchttpd-4W.zip).
I have no Idea how to install and play this.
do I have to Replace Apache File Folder with all content on mchttpd-4W.zip?
Is there any document how to use it?
Sorry for my Newbie question ...
I think.... I still don't understand the step. how to solve my problem.

Image

Now ... this is what i have in my mind
1. After Install Livecode Server and Apache
2. Install mchttd.mc
3. Create an Android Apps using socket connection to LiveCode Server (GET and POST method to write file)

Is it a right way? I hope ... I'm still on the track
capellan wrote:Hi Gilar,

Check if this stack (posted by Richard Gaskin) could help in some way to receive a text file from Android:
http://forums.livecode.com/viewtopic.ph ... 77#p119706

these forum threads:
http://forums.livecode.com/viewtopic.php?f=15&t=20897
http://forums.livecode.com/viewtopic.php?f=23&t=22777
http://forums.livecode.com/viewtopic.php?f=7&t=6007

and these Livecode lessons created by RunRev and BYU University:
http://lessons.livecode.com/m/4071/l/12 ... ng-sockets
http://livecode.byu.edu/internet/IntroToSockets.php

Richard Gaskin wrote:

In its simplest form. a Web sever is just an app that responds to requests on port 80. To show off MetaCard's socket support Scott Raney made mchttd.mc, a simple stack that acts as a Web server.

Andre made extensive enhancements to mchttpd, but he's interested in a level of scaling for public sites, which can't be done with conventional CGI in a single-threaded engine, so he's moved on to other projects.

The problem isn't that FastCGI became broken, but that it was never truly feasible, since it requires any app using it to support multiple threads to handle concurrent connections.

For small workground mchttpd and similar socket servers can be a good solution.

With Dr. Raney's permission, I've added a necessary header-output adjustment to his original stack, and have posted it here, under MIT license:
http://www.fourthworld.net/lc/mchttpd-4W.zip

All that said, Apache is a very good Web server, and CGI is efficient enough for a wide range of public web sites. While there's interest in the community in exploring threading additions to the engine needed for FastCGI for large-scale deployments, for most of us CGI is fine.
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Mon Feb 27, 2017 5:41 am

I try to open "mchttpd_2b-4W.mc" and "answerclient.mc" with Livecode App (oh god ... i don't know if this extension can open with Livecode)

Then I got this information
......
A server listens on a specified port number for incoming requests from clients. This listening process is started with the accept command.
To request data from a server, a client creates a socket to the server on the specified port. When the socket connects, the client sends a request for the server to do something by writing to the socket. In the case of HTTP, the client requests a file or sends in data from a form which is to be processed (typically by a Common Gateway Interface (CGI) application) and the file or result is returned to the client.
...........
For html files, which are retrieved with the HTTP GET command, only the first line of the request is really needed since it contains the file name the client wants. For the HTTP POST command, all of the data is required since the data the client is uploading is on lines after the first one. If a large amount of data is being posted to the server, more than one read command may be necessary to get it all (the total size is included in the header information).
Since a server typically works with many files, a "root" directory is typically defined for it when it is installed. MCHTTPd gets its "root" directory from the directory it is installed in.
In their root directories, HTTP servers usually have an "html" directory where the web pages and images are stored and a "cgi-bin" directory for scripts which process data from HTML forms (note that .mt files only work on UNIX OSes). MCHTTPd has a third directory, "stacks-bin", which contains stacks whose scripts it can call with start using instead of typical cgis.This improves performance considerably and also makes scripting server-side applications much easier. The MCHTTPd distribution contains a trivial example of such a stack.
.........

With Android apps, can we ask server to create XML file and store it in PC with GET/POST Command. ?
I'm still trying the function of "mchttpd_2b-4W.mc" and understanding how it works.
Gilar | from INDONESIA

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Write XML file from Android to PC over WiFi connection

Post by FourthWorld » Mon Feb 27, 2017 6:30 am

.mc was the original file extension for LiveCode (back then it was called MetaCard). You should be able to use File-> Open, maybe changing the filter to "All File". Or just change the file extension to ".livecode".

Have fun. Once you get the hang of writing custom servers like that you may find yourself coming up with all sorts of other fun projects to use them on.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Write XML file from Android to PC over WiFi connection

Post by gilar » Mon Feb 27, 2017 10:30 am

FourthWorld wrote:.mc was the original file extension for LiveCode (back then it was called MetaCard). You should be able to use File-> Open, maybe changing the filter to "All File". Or just change the file extension to ".livecode".
Have fun. Once you get the hang of writing custom servers like that you may find yourself coming up with all sorts of other fun projects to use them on.
Hi ... Richard ... Thank you very much. Now ... i have a progress on doing it.

But I still no Idea how to use it.
Could you please .. give me a little explain, how to use MCHTTPd.
How to Install it? Where Should I put all file on mchtppd-4W.zip?
Do I still need LiveCode Server and Apache On?

just now
I open "MCHTTPd.mc" and than I push "START SERVER" button (Server on)
Then check with my "CasparCG client" (a Client Appkication which made with LiveCode), change the port to 8080.

the Result is:
I can send XML message (not a file) into LOG text field like this.

Code: Select all

404 Not Found 2/27/17 15:53:25 CG 1-9 ADD 1 score 1 "<templateData><componentData id=\"eventImage1\"><data id=\"text\" value=\"\" /></componentData><componentData id=\"Team1Image\"><data id=\"text\" value=\"\" /></componentData><componentData id=\"Team2Image\"><data id=\"text\" value=\"\" /></componentData><componentData id=\"Promo1Image\"><data id=\"text\" value=\"\" /></componentData><componentData id=\"event1\"><data id=\"text\" value=\"EVEN NAME\" /></componentData><componentData id=\"sktim1\"><data id=\"text\" value=\"\" /></componentData><componentData id=\"sktim2\"><data id=\"text\" value=\"\" /></componentData><componentData id=\"score1\"><data id=\"text\" value=\"0\" /></componentData><componentData id=\"score2\"><data id=\"text\" value=\"0\" /></componentData><componentData id=\"timer1\"><data id=\"text\" value=\"00\" /></componentData><componentData id=\"timer2\"><data id=\"text\" value=\"00\" /></componentData><componentData id=\"timer3\"><data id=\"text\" value=\":\" /></componentData></templateData>"
I try with Android Apps too
The result is ... I can send a command to server LOG:

Code: Select all

404 Not Found 2/27/17 16:17:42 XPT MLE:2:PGM:IN:2
404 Not Found => Can we make it Found? What Should I do?

What I want is ... My Android Apps will create and XML file to PC ( if it's possible via MCHTTPd or Apache)
Is it possible?
Gilar | from INDONESIA

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Write XML file from Android to PC over WiFi connection

Post by AxWald » Mon Feb 27, 2017 11:14 am

Hi,

just a thought: Why don't you just set up a FTP Server on your Win machine? FileZilla Server for instance?

This should make things ways less complicated ...

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply