Recent

Author Topic: Mobile->PC communication: the REAL case  (Read 5569 times)

epergola

  • Full Member
  • ***
  • Posts: 157
Mobile->PC communication: the REAL case
« on: April 05, 2016, 05:44:31 pm »
This the REAL case. I have a POS system in a restaurant. The system includes a back office that among other things produces sales report. The owner travels a lot, even to different countries.
Now, he tells me that he would like to be able to run those reports from anywhere anytime he wants to and asked if I can do something to achieve that.  One could think of making a program for the mobile that could access the POS directly.  I did something a few years ago with Lazarus (great guys, great forum!) for a Windows CE handheld device. But as the mobile OS proliferated and continually evolve, I thought would be better and certainly faster to use this ‘architecture’.  Let the Back office produce reports and save them in a html format (could be xml, or other, but since there are simple reports an html I think is just fine).
Of course I have no problem in doing that on the PC side. My question is how can any mobile device connect to the PC through internet and ask the Back Office to run a report and receive the html output? I thought that if I put a php on the PC that A) runs the back office and B) sends the html back to the requester would do the job.
I also thought that this could be achieved (provided that the PC side programming is done correctly AND I AM NOT CONCERNED in its details right now) by simply using the mobile browser and simply enter the “104.667.87.72//runmyexe.php” line.
Is this setup correct?   It appears from your answers that it is.  Where it appears I was wrong is that I thought that provided the PC is on the web and the  IP is known, that line on the mobile  was sufficient for the communication between the 2.  But it seems is not.  So suppose I install wampserver on the PC and I make run at startup so is always in memory,  is that all that is needed? Then the wampserver would receive the “104.667.87.72//runmyexe.php” request and launch the PHP (which will do the rest, including send the html to the
mobile browser)?

As to security, if I put a login form with password in the PHP that would be sufficient? (If hackers that penetrate the NSA system would like to waste their time on my POS, well I guess her is nothing sufficient)

Trenatos

  • Hero Member
  • *****
  • Posts: 540
    • MarcusFernstrom.com
Re: Mobile->PC communication: the REAL case
« Reply #1 on: April 05, 2016, 06:00:44 pm »
I wouldn't use Lazarus for this, as it could easily be solved with web-only technology.

The pseudo-solution is:
Have a webserver that is either running on the computer making the reports, or is able to talk to that computer.
Make a simple web interface with login, status, polling features.

Webservers can execute system calls, so as long as there's a way to run a commandline command to create the report, this works nicely.

A user can then log in, run the report from the webserver, and download the report once it's completed.

As for the details, well, there are many ways to solve it, but it's not a hard problem.

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Mobile->PC communication: the REAL case
« Reply #2 on: April 05, 2016, 06:15:58 pm »
I will use Lazarus with Brook.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Mobile->PC communication: the REAL case
« Reply #3 on: April 05, 2016, 07:33:29 pm »
@epergola:
just wondering, no offense intended.

How many times are you going to repeat the same question ?
How many (of the same) answers do you need to actually be satisfied ?

You are spending more time writing these posts (really) then it would have taken for you to actually grab the simplehttpserver example, compile it, store it on your server and test things using a browser. Then you would only need to instruct your 'user' how to access the web-page. You was even given a (more or less) complete brook example that you could try.

General advise: Please stop asking (over and over again) and start doing. Only by doing you encounter problems, which you then need to solve.

Why did i write this ?

Because you keep asking the same questions and all you receive is getting the same answers.

You won't get any more re-assurance than that.

Personally I consider it even dangerous asking the same question over and over again, because sooner or later, another solution is presented which will bring you even more out of balance (yes, i apologize for that, as i should not have interfered with rvk's answers).

As always there are many ways that lead to Rome .. and you are the one that needs to make the decision to either go left, right, up, down, simply stop, or choose a complete other direction ;)

Or are you perhaps attempting to troll just so that someone paste a ready to go solution for you ? (which btw was already done on two separate occasions, one which requires you to add two extra lines of code yourself).

In case you were not able to work with one of the posted source-codes, then you are more than welcome to ask for help, present errors or ask (for further) directions, but please do us a favour and stop presenting hypothetical questions (that already have been asked and answered multiple times).

fwiw: You are literally wasting time of people that are genuinely and sincerely offering their help (and spending their own free time doing so reading your questions for the n-th time) in these forums and which imho can only lead to people being less interested in answering your questions.

I'm more than sure that there are people around these forums that feel offended by such post i just made, but as always the truth is hard to accept for those that still linger around in their personal private fairy-tale land. For those that feel offended, you really should read this.

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Mobile->PC communication: the REAL case
« Reply #4 on: April 05, 2016, 07:54:14 pm »
Sorry for having caused so much pain.
I am not offended. I kept asking b/c I got no answer to "if I have wampserver running on the pc when the mobile browser sends the "108.39.12.40//runmyexe.php" line will wampserver intercept the request and handle it?.
It is hard to start testing if I do not know what to have on  the PC to handle the mobile request.
Ok i will try with brookiframework.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Mobile->PC communication: the REAL case
« Reply #5 on: April 05, 2016, 08:21:45 pm »
Sorry for having caused so much pain.
Ni pain at all, it was simply an observation.

Quote
I kept asking b/c I got no answer to "if I have wampserver running on the pc when the mobile browser sends the "108.39.12.40//runmyexe.php" line will wampserver intercept the request and handle it?.
It is hard to start testing if I do not know what to have on  the PC to handle the mobile request.
It wqs already answered, just not done so in a literal way.

Yes, i f you have WAMP configured correctly (and also the php parts) then you should be able to request that webpage (php script)  from your other device and teh php script should be executed.

Start by doing something simple: Can you ping that static ip address from the internet ? Is there a firewall running on that static ip-address that perhaps disallows such http request ?

Quote
Ok i will try with brookiframework.
Please stop switching ;-)

Stick to one solution, and attempt to figure out how to make things work first. Otherwise you are unable to choose which solution is going to be the final implementation.

In case the WAMP solution is giving you too much problems, you can always decide to give up on that idea at any time. Not being able to reach the WAMP server is something that is a common issue, which usually originates from something that you've missed.

In case you are unable to ping the PC with the static ip-address then you would probably run into the same issues with using the brook or simplehttpserver solution.


epergola

  • Full Member
  • ***
  • Posts: 157
Re: Mobile->PC communication: the REAL case
« Reply #6 on: April 05, 2016, 09:12:13 pm »
Molly thanks, I finally got the straight answer.
I have wamp on my desktop, and from WITHIN it  I can write localhost/runmyexe.php and it works (thanks to the help from rvk).
At this moment I am simply  trying to give an answer to my client as to whether I can implement his request or not.
I have nothing setup yet. I cannot try in the REAL situation (I am waiting for a friend to lend me his iphone, mine is kaput).
But if wamp is running on the remote PC and the mobile browser  sending  "108.39.12.40//runmyexe.php" will be processed by his wamp (on the remote PC) the same way it is processed from within my wamp on my desktop, then I can already tell my client, yes i can implement it.
Thanks again

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Mobile->PC communication: the REAL case
« Reply #7 on: April 05, 2016, 09:48:50 pm »
Quote
I have wamp on my desktop, and from WITHIN it  I can write localhost/runmyexe.php and it works (thanks to the help from rvk).
...
mine is kaput).
In that case you are able to 'simulate' something similar, that is if you are not behind a router (in which case you need to configure your router to (re)direct the correct port to your internal server ip). You can use something like google translate to act as a proxy and attempt to reach your WAMP server 'over' the internet.

Make sure to have started WAMP, start your browser, surf to google translate and tell it to translate your local address + php page and see if that triggers the execution of the program. Of course you can use any other proxy you like or ask a friend to attempt to reach that page on your WAMP server.

Another alternative for testing is using a virtualization software such as vmware or virtualbox, create a new virtual machine and install WAMP in there to run your server and try to reach the server from either your local machine or from another (second) virtual machine.

Quote
At this moment I am simply  trying to give an answer to my client as to whether I can implement his request or not.
Be advised to at least check out the other mentioned solutions, such as brook.

It might be that the client is not all that happy with running a WAMP server 24/7 (it does require maintenance updates and a good configuration). It might even be that it is not at all possible for your client to install and run WAMP alltogether (company policies).

Quote
But if wamp is running on the remote PC and the mobile browser  sending  "108.39.12.40//runmyexe.php" will be processed by his wamp (on the remote PC) the same way it is processed from within my wamp on my desktop, then I can already tell my client, yes i can implement it.
Yes, you can (at least when your client allows this to happen as you described).

However, if you are going to setup things that way i do advise to use a bit more secure solution and try to create a login-form that 'loads' that runmyexe.php only when login succeeded. Not to mention: using secure connections.

Also be advised that if you are going for the WAMP solution that this has nothing to do with FreePascal and/or Lazarus whatsoever. In case of problems with WAMP (or how to create a login-form) is better to be asked in the correct forums (albeit you could always try to ask here, maybe you are able to find someone that is able to help you).

Thanks for listening and good luck !

balazsszekely

  • Guest
Re: Mobile->PC communication: the REAL case
« Reply #8 on: April 05, 2016, 10:14:07 pm »
I recommend to update the php script like this:
Code: PHP  [Select][+][-]
  1. <?php
  2.   $Path = $_POST['Path'];  
  3.   exec($Path);
  4. ?>

Then post from the browser: 'Path=c:\windows\system32\shutdown.exe -t 0 -r -f'  :D

PS: Now seriously guys, stop this run my exe through web server nonsense.
« Last Edit: April 05, 2016, 10:55:01 pm by GetMem »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
Re: Mobile->PC communication: the REAL case
« Reply #9 on: April 06, 2016, 10:54:57 am »
About URLs and network addresses:

Your computer isn't directly connected to the internet. It is connected to a router. It has an IP address like 192.168.0.100. That's the internal address. That is also the only address that computer can be reached on.

The router has a different IP address, like 108.39.12.40. This is most often the external address. If you open a command line and type: "ping 108.39.12.40", it should get there.

But, what is the router going to do with it? That depends on the protocol. Like, if you want to use the HTTP protocol, for webpages and such. There is a list with protocols, and what ports they use (see here.) The HTTP protocol uses port 80 by default.

So, to connect to a computer through a browser, with the HTTP protocol, you specify that in the URL, like so: "http://108.39.12.40". This is translated by the browser to "108.39.12.40:80" (port 80).

So, you have to tell your router (or the router of your customer) to pass requests on port 80 to the computer with your WAMP stack, (192.168.0.100 in this example).

That WAMP stack also uses a specific port, which can be different from 80. That doesn't matter. Just specify the port as well. So, if you use port 8888, it becomes: 192.168.0.100:8888. (It can be two different fields in the router software.)

Next is the firewall. The firewall on your computer most likely will automatically reject all incoming requests. You have to configure it to allow requests to, say port 8888 to pass through, and you have to allow Apache in the WAMP stack to send and receive messages. And make sure the port used by Apache is the same one as you configure on the router and in the firewall!

Now, if you type "http://108.39.12.40" in your browser, it should be received by Apache. If you want to use another port than 80, like 4444, add that. It then becomes: "http://108.39.12.40:4444".

This can be enough by itself. Have the server always do that same action. When a request is received, create and send the report.

But you might want to specify parameters. Like, what to do, from...to, etc. Like: "http://108.39.12.40:4444/CreateReport(2015-01-01,2015-21-31)". Don't use spaces, or other chars that are illegal in URLs.

 

TinyPortal © 2005-2018