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

Write XML file from Android to PC over WiFi connection

Post by gilar » Sat Feb 18, 2017 4:21 pm

Hi ....

first i have succes to write XML file on PC
here is the thread http://forums.livecode.com/viewtopic.php?f=8&t=28836

Now I'm trying to Write an XML file from Android apps over WiFi connection
here what i've done:
1. Create Android apps and Deploy it in Stand alone (succes)
2. Create Windows apps and Deploy it in Stand alone (succes)
3. on PC, create a share folder on C (//DRACO-PC/DracoXpression/)
4. Trying Win application on local host succes to create an XML file.
5. Trying Android apps from my phone (fail)

Here is button "GENERATE" XML

Code: Select all

on mouseUp
   startXML
   startTag "DracoFootballXpression"
   startTag "Statistic"
   startTag "Title"
   writeNode "category_1", line 1 of field "scat_fld" of card 002
   writeNode "category_2", line 2 of field "scat_fld" of card 002
   writeNode "category_3", line 3 of field "scat_fld" of card 002
   writeNode "category_4", line 4 of field "scat_fld" of card 002
   writeNode "category_5", line 5 of field "scat_fld" of card 002
   writeNode "category_6", line 6 of field "scat_fld" of card 002
   writeNode "category_7", line 7 of field "scat_fld" of card 002
   writeNode "category_8", line 8 of field "scat_fld" of card 002
   writeNode "category_9", line 9 of field "scat_fld" of card 002
   closeTag
   startTag "Value"
   startTag "Home_Value"
   writeNode "HValue_1", line 1 of field "ValueStatA_fld" of card 002
   writeNode "HValue_2", line 2 of field "ValueStatA_fld" of card 002
   writeNode "HValue_3", line 3 of field "ValueStatA_fld" of card 002
   writeNode "HValue_4", line 4 of field "ValueStatA_fld" of card 002
   writeNode "HValue_5", line 5 of field "ValueStatA_fld" of card 002
   writeNode "HValue_6", line 6 of field "ValueStatA_fld" of card 002
   writeNode "HValue_7", line 7 of field "ValueStatA_fld" of card 002
   writeNode "HValue_8", line 8 of field "ValueStatA_fld" of card 002
   writeNode "HValue_9", line 9 of field "ValueStatA_fld" of card 002
   closeTag
   startTag "Away_Value"
   writeNode "AValue_1", line 1 of field "ValueStatB_fld" of card 002
   writeNode "AValue_2", line 2 of field "ValueStatB_fld" of card 002
   writeNode "AValue_3", line 3 of field "ValueStatB_fld" of card 002
   writeNode "AValue_4", line 4 of field "ValueStatB_fld" of card 002
   writeNode "AValue_5", line 5 of field "ValueStatB_fld" of card 002
   writeNode "AValue_6", line 6 of field "ValueStatB_fld" of card 002
   writeNode "AValue_7", line 7 of field "ValueStatB_fld" of card 002
   writeNode "AValue_8", line 8 of field "ValueStatB_fld" of card 002
   writeNode "AValue_9", line 9 of field "ValueStatB_fld" of card 002
   closeTag
   closeTag //Value
   closeTag//Statistic
   closeTag // Draco Football Xpression
   put the xml of card STAT into tXMLFinal
put textencode(tXMLFinal,"UTF8") into url "binfile://DRACO-PC/DracoXpression/Statistic.xml"
end mouseUp

Here is the Stack Code

Code: Select all

on preOpenStack
   set the fullscreenmode of me to "exactFit"
   set the fullscreen of this stack to true -- fullscreen mode
end preOpenStack

on closeStackRequest
quit
end closeStackRequest

on closeStackRequest
if revXMLTrees() is not empty then revDeleteAllXMLTrees
quit
end closeStackRequest

//================================================ UPDATE XML DracoData.XML
local _tags
local _xml
local _level
local _tabs

function q pText
   return quote & pText & quote
end q

on startXML
   put "<?xml version=" & q("1.0") & " encoding=" & q("UTF-8") & "?>" & return into _xml
   put 0 into _level
   put empty into _tabs
   put empty into _tags
end startXML

on startTag pTag
   put _tabs & "<" & pTag & ">" & return after _xml
   add 1 to _level
   put pTag into _tags[_level]
   put tab after _tabs  
end startTag

on closeTag
   delete char 1 of _tabs
   put _tabs & "</" & _tags[_level] & ">" & return after _xml
   # Do a 'delete variable _tags[_level]' if you really want to clean the array as you go 
   subtract 1 from _level
end closeTag

on addAttribute pAttribute, pValue
   # This should go into the last tag, but as we have "proper XML" so far we can backtrace two chars (">" and newline)
   put space & pAttribute & "=" & q(pValue) before char -2 of _xml
end addAttribute

on writeContent pContent
   put _tabs & pContent & return after _xml
end writeContent

on writeNode pNode, pValue
   put _tabs & "<" & pNode & ">" & pValue & "</" & pNode & ">" & return after _xml
end writeNode

getProp xml
   return _xml
end xml
//================================================ UPDATE XML DracoData.XML
Any one could point me into right direction?
Comment and help would be appreciate



Gilar Kadarsah
Last edited by gilar on Tue Feb 21, 2017 6:05 pm, edited 1 time in total.
Gilar | from INDONESIA

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

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

Post by SparkOut » Sat Feb 18, 2017 11:49 pm

Firstly, can the android device resolve the pc name ok? What if you change "draco-pc" to the ip address of the pc?

Secondly what are the permissions on the dracoXpressions folder? I expect you would have to have user credentials passed from the android connection to be allowed to write there.

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 » Sun Feb 19, 2017 4:20 am

SparkOut wrote: Firstly, can the android device resolve the pc name ok? What if you change "draco-pc" to the ip address of the pc?
I have change draco-pc into PC ip adress and still fail to write XML file
Is this need something like socket and port connection?
SparkOut wrote: Secondly what are the permissions on the dracoXpressions folder? I expect you would have to have user credentials passed from the android connection to be allowed to write there.
I'm not sure about this
this is what i have done
Image

and this is Stand Alone application setting
Image
Image

How about inclusion ? is this influence for standalone application?
Gilar | from INDONESIA

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 » Sun Feb 19, 2017 4:50 am

I have check with windows application from Another PC on the Network ... I can make it

I use this URL and I succes to create XML file

Code: Select all

 
binfile:\\DRACO-PC\DracoXpression\Statistic.xml
So i think this is about Android Application
Any one know, what i've missed up?

Comment and help would be appreciate


Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

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

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

Post by SparkOut » Sun Feb 19, 2017 9:28 am

Your Android device will not be a member of the homegroup so sharing that way you will have no success. If you change sharing to specific people and then select 'everyone' and under the advanced network properties turn off prompting for passwords then you might have a chance. That would be REALLY bad practice, although if successful you might then find a way to harden the pc share a bit more afterwards.
A better approach would be for your Android app to post to a server on the pc, say livecode server with a script that handles file upload, which will then store it in your shared folder. Or possibly run an app on the pc listening for socket connections.

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 » Sun Feb 19, 2017 12:11 pm

Hi SparkOut ... thanks for quick replay...
SparkOut wrote:Your Android device will not be a member of the homegroup so sharing that way you will have no success. If you change sharing to specific people and then select 'everyone' and under the advanced network properties turn off prompting for passwords then you might have a chance. That would be REALLY bad practice, although if successful you might then find a way to harden the pc share a bit more afterwards.
Still no Luck with doing this ...
Image
Image
SparkOut wrote: A better approach would be for your Android app to post to a server on the pc, say livecode server with a script that handles file upload, which will then store it in your shared folder. Or possibly run an app on the pc listening for socket connections.
I try to look out this way ... but I don't understand where i have to start to doing this.
I think I don't understand what is Livecode server mean.
I have download it, then I run "livecode-community-server.exe"
and nothing changes

do I hve to create a kind a server application?
Then Where i have to create it?
Can I create it with livecode 7.1.4 Community Edition?

Thanks


Gilar Kadarsah
Gilar | from INDONESIA

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 » Sun Feb 19, 2017 7:26 pm

Still strugle to write XML file from Android into PC

I checked this totorial https://www.maketecheasier.com/share-wi ... s-android/
and follow it

I'm using this "ES File Explorer" on Android https://play.google.com/store/apps/deta ... ndroid.pop
to check if my Android can acces share folder to PC
i tasted and it works, read and write.
but I still cannot write XML file with my android apps

I also tried to install XAMPP and and change mycode
put textencode(tXMLFinal,"UTF8") into url "binfile://MYPC-IP/Statistic.xml"

Code: Select all

on mouseUp
.
.
.
.
.
   writeNode "AValue_8", line 8 of field "ValueStatB_fld" of card 002
   writeNode "AValue_9", line 9 of field "ValueStatB_fld" of card 002
   closeTag
   closeTag //Value
   closeTag//Statistic
   closeTag // Draco Football Xpression
   put the xml of card STAT into tXMLFinal
put textencode(tXMLFinal,"UTF8") into url "binfile://MYPC-IP/Statistic.xml"
end mouseUp
Still no luck to write XML file from my Android Apps

I checked from my Android with browser (on browser i type: MY-PC IP) then I can access XAMPP dashboard on PC
Gilar | from INDONESIA

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

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

Post by capellan » Mon Feb 20, 2017 8:19 pm

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.

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

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

Post by capellan » Tue Feb 21, 2017 3:10 am

Hi Gildar,

I tested the stack mchttd.mc (a stack that works as a Web server)
and it works fine from the web browser in the same computer
where it is running, but when I try to access the stack server
from an Android Tablet, an error message tells me that
the Wireless Router is blocking the incoming request.

Are you sure that your router is not blocking what you are
trying to do?

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 » Tue Feb 21, 2017 4:43 pm

Hi capellan, thanks for your explanation

I have succesed to create a Client Apps with Livecode
But I never create a Server Apps with it.
So,I think i have to learn more about LiveCode Server

There is several CasparCG Client I have created with livecode
I connect it to CasparCG Server

*)
CasparCG ---> http://www.casparcg.com
here what I have done with livecode
https://www.youtube.com/watch?v=TTZpnb2eAEU&t=164s
https://www.youtube.com/watch?v=BQiS995n07s&t=51s
capellan wrote:Hi Gildar,
Are you sure that your router is not blocking what you are
trying to do?
I don't think so
I have checked it with my Apps like this,
https://www.youtube.com/watch?v=47LofgBODCY
Gilar | from INDONESIA

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 » Tue Feb 21, 2017 6:03 pm

Image
SparkOut wrote:Your Android device will not be a member of the homegroup so sharing that way you will have no success. If you change sharing to specific people and then select 'everyone' and under the advanced network properties turn off prompting for passwords then you might have a chance. That would be REALLY bad practice, although if successful you might then find a way to harden the pc share a bit more afterwards.
Still trying for this method
I found this is about SMB Protocol problem
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

to connect SMB Protocol we must open firewall and PORT 137, 138, 139 and 445
http://www.thewindowsclub.com/block-ope ... 8-firewall

there is tips from Apple
https://support.apple.com/en-us/HT204445

found this tips
http://www.tannerwilliamson.com/windows ... a-smb/394/

Still no No luck ....
Last edited by gilar on Wed Feb 22, 2017 5:23 am, edited 1 time in total.
Gilar | from INDONESIA

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 » Wed Feb 22, 2017 4:57 am

Image


Hi capellan ....
Now i'm trying to understand about CasparCG Server, CGI and Installing Apache Server

# First I follow this Tutorial
http://lessons.livecode.com/m/4070/l/36 ... ode-server

Then Trying to Install "Apache Server" from here
http://httpd.apache.org/download.cgi#apache24
but I have no idea how to Install it, then i search on youtube found this tutorial
https://www.youtube.com/watch?v=17qhikHv5hY&t=418s
different link for Apache
https://www.apachelounge.com/download/ (is this ok if i use this installer?)
Is there any different between them? (Apache)
if I have installed XAMPP do I need Install Apache Server Again?
because when I look it to XAMPP Folder there is Apche on it.

# Second Lets say if XAMPP is ok for doing webserver.
I'm running XAMPP and start Apache Server
Image

then i run my android Apps
I change my code

Code: Select all

put textencode(tXMLFinal,"UTF8") into url "binfile://MYPC-IP:80/Statistic.xml"
or 
put textencode(tXMLFinal,"UTF8") into url "binfile://MYPC-IP:443/Statistic.xml"
or
put textencode(tXMLFinal,"UTF8") into url "binfile:http://MYPC-IP:80/Statistic.xml"
or
put textencode(tXMLFinal,"UTF8") into url "binfile:http://MYPC-IP:443/Statistic.xml"
or
put textencode(tXMLFinal,"UTF8") into url "binfile:http://MYPC-IP/Statistic.xml"
or
put textencode(tXMLFinal,"UTF8") into url "binfile://MYPC-IP/Statistic.xml"
80 = port
443 = port

still no luck


please correct me if I'm wrong
I want to make sure, if I'm on the right track

Comment and help wouldbe appreciate
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 » Wed Feb 22, 2017 7:47 am

Hi gilar

You don't need to load Apache again if XAMPP is installed. You just need Apache to run as a web server so that the host end can do something in response to your Android connection attempts, so XAMPP fits the bill here.

You do need to configure things on the server side to take action though. With XAMPP there are two ways you could go.

You could configure XAMPP as an FTP server setting up a user account and directory to upload to.

Or you could set up scripts on the XAMPP Apache server to handle POST data - either php or livecode (server) scripts, but livecode server would need to be installed and configured to work in the XAMPP environment.

Either way, you need to change the approach to saving the file. You cannot put it into url ("binfile:blahblah") - that assumes you are working directly with a compatible file system, which you have discovered isn't working for you.

look up commands with reference to FTP and POST (and tsNet library) in the livecode dictionary. I have to dash now but hopefully someone will be able to give more specifics before I get back tonight.

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 » Wed Feb 22, 2017 9:51 pm

See this guide to setting up FileZilla FTP server in XAMPP.
When it comes to adding the shared folder, you can select your preferred destination.

Test it with an FTP client to upload a file.

Then (if you have an Indy LC licence) try editing this to match your PC's IP address and details and user account that you set up:

Code: Select all

   tsNetInit -- initialise the tsNet library
   put specialFolderPath("documents") & "/myFileToUpload.xml" into pFile -- choose your file
   put "ftp://x.x.x.x:21/<path to shared FTP folder>" into pUrl -- where x.x.x.x is the IP of your server PC
   -- :21 assumes you have used the standard FTP port in FileZilla server
   -- (the YouTuber uses 81, but that's changing it unnecessarily)
   -- and <path to shared FTP folder> is for you to specify
   put empty into pHeaders -- redundant variable initialisation
   put empty into pOutHeaders -- redundant variable initialisation
   put empty into pBytes -- redundant variable initialisation
   put "myFTPUserName" into pSettings["username"] -- add credentials
   put "MyFTPpassword" into pSettings["password"] -- add credentials
   get tsNetUploadFileSync(pFile, pURL, pHeaders, pOutHeaders, pResult, pBytes, pSettings)  
   -- let the library take the strain of uploading to your target location
   -- check "it", check "the result" and check "pResult" to see what happened
   tsNetClose -- close the tsNet library
Without tsNet I don't think there is a libURL option for Android to use FTP. But if necessary you could POST the file to the Apache server on which you would have a script to handle the upload and saving to the correct location. See how you go with FTP first.

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 12:49 am

Hi SparkOut .....
Thank you very much, Now I try to learn how to use FTP
SparkOut wrote: Then (if you have an Indy LC licence) try editing this to match your PC's IP address and details and user account that you set up:
I use Livecode Community 8.1 is it possible?
I use your code but get an error at

Code: Select all

tsNetInit -- initialise the tsNet library
Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

Post Reply