Smack connection close during file upload via retrofit - php

I'm developing an XMPP client on Android using Smack library and Ejabberd as my XMPP server.
so far everything is working good, but whenever Users start uploading large files and sending lots of messages rapidly, their connection got close from server.
I get following from debuger:
connection Closed Error Parser got END_DOCUMENT event
uploading is handled via retrofit library
I checked Ejabberd config, so user are allowed to send messages rapidly and config of php upload server allows large files uploading.
also Ejabberd and php upload server are not in the same host.
I just can't get where the problem is, is it from smack, ejabberd or even android itself.

Related

AWS EC2 server refusing Ionic/Capacitor/Android connections to PHP files

I have recently begun building an Angular Ionic app which connects to PHP scripts on an AWS EC2 server. Everything works fine except for when I try to connect through Android once the app is built on my phone.
The response is a simple 404 response with no additional information. When I look at the log on Android Studio I see the following response:
E/Capacitor: Unable to open asset URL: [api address]
I have reduced both the HttpClient call on the frontend and the php file on the backend to their most simple forms and yet still nothing:
<?php
echo "Hello";
?>
I know that Capacitor was updated to 3 only a couple of months ago and am concerned that it is related to that. I am using PHP 7.
UPDATE
The issue was indeed cleartext but the issue was made more complicated by the fact that HttpClient was not catching the error and so I was simply getting back an unknown failed response.
In order to first see that it was cleartext I first had to change HttpClient for the Native HTTP plugin and check the logs whilst testing on my phone (HTTP will not work through the browser).
Only then did I notice that I hadn't changed the config file correctly.
As long as your PHP web server is not running on the Android device directly trying to connect to localhost / 127.0.0.1 won't work and you need to use another domain / IP your web server is available on and which the Android device can access. You can also check this by simply opening the URL in the browser of the Android device.
If that is not feasible for you you could also use port forwarding via adb to forward a port of your web server to a local port on the Android device.
If you use another domain / IP make sure your web server is not listening to local connections only and is not blocked by a firewall or similar.
Also if you are using an unencrypted connection (i.e. http instead of https) you might need to enable the cleartext config option in you Capacitor config.

How to upload a PHP file on Azure

Right now I have a localhost database using WAMP server.
I connect and insert data to this DB by making a POST request to the file's PHP link (e.g localhost/sensor_data/connect_To_DB_And_Insert_Data.php).
I want to do the exact same thing with Azure SQL so my database won't be local anymore but on a remote server.
I have already created a database but I don't know how to upload a PHP file that can be accessed online using a link. There are so many documentations that I'm kind of lost and I didn't find an answer to this yet.
So my question is, how do I upload a PHP file on Azure, that it can be accessed by a link, so I can insert data to the database by making a post request to that link ?
Firstly, you just need to change the connection string in your PHP code. Then your PHP application will be able to connect to Azure SQL. In this way, you do not need to create any Azure host server (Web app or VM).
You can get the connection string on Azure portal:
Attention, as Azure SQL has enabled firewall. So, if you want to connect to it from your local server, you need to add your IP to the allowed IP list
However, as #UkraineInTheMembrane suggested in the comment, you can also to use Azure Web App or VM to host your PHP application.
With Azure Web App, here is a get-started tutorial for PHP: Create a PHP web app in Azure , in this tutorial, git is used to manage your code.
There are also many other approaches to upload your code to azure web app: https://learn.microsoft.com/en-us/azure/app-service/deploy-zip

php client detect file updates on server

I have a server:
ubuntu, running Xampp.
multiple clients:
Raspberry pi, running Apache
all connected via LAN network
I have a PHP code on the server that does the following:
gets information from the database
write it in json files
Accepts REST API request and sends response
on the client side, a php code that does:
send REST API calls
gets the response and write it to a text file
The database might be updated anytime, and the json files will be updated accordingly.
I want the clients to execute the code whenever the json files are updated.
Is there any way to make the clients monitor these files?
or make the server send a signal to all clients when the files are updated?

How to make a php file in bluehost that is reachable from ios app and mysql

I have already made my app so that it works on the ios simulator and a localhost server. Now I want to make my app so that it is reachable on ios devices. I have a website that is hosted by bluehost. If I could just write up the same php files that I wrote in the local server and it was reachable from the app and mysql, I think it would do the trick. Unfortunately, I don't know how to do this. Is there a way to access my website's mysql from my ios app through php files (which are also on bluehost)?
Thanks in advance!
You need one of the three (well you can make your own mode as well, but these are standard)
JSON
XML
CSV
Your php file on bluehost would be an URL which would open a stream and push information from the database and your IOS app needs to read it.

How to communicate FTP transfer with standalone PHP Server?

I have a Ubuntu Server on which I have my Apache and FTP server (I am using Proftpd server). I have a small PHP CMS and for database I am using MySQL server. This was my server side environment. Now on client side I have a C# ftp client which I use to download the file from FTP server. Also, this C# client communicates with my PHP CMS.
So in short there are two communications occurs at a time
1. C# client and FTP server for file transfer.
2. C# client and PHP CMS for some other work.
So, now what I want is real time progress (progress bar) of my ftp transfer on one of my CMS webpage.
Obviously one of thing I can do is that I can tell my C# client to upload it's download progress to PHP server using some web service or web socket and then I can show the progress of ftp transfer(basically progress of downloading of C# client).
But before doing this I just want to know that is it possible for my PHP server to check what FTP server is doing. Since, no communication occurs between them I don't know how to accomplish it? I have a MySQL server and I know that proftp can communicate with MySQL server and it has some predefined table in which I can store whatever is ftp server doing. But will it possible to use it to show a real time progress? Is their any other technique to do this or will I have to force my C# client to do it?
From what you say, you have no need to talk to the FTP server at all (except to download the file, of course). Your FTP client could upload the FTP transfer status to a Web socket (and why could it not display it directly?), there to be recovered by the CMS and shown in the page. By using sessions, you do not even need to actively save that information anywhere, provided the Web socket call properly initializes the session cookies.
In the FTP client download callback function just add a call to send the progress status to the server. There, a scriptlet will save it into, say, $_SESSION['download_status']. An AJAX call on the CMS page can then retrieve it and display it periodically.
Don't forget to also upload FTP session and exception status (transfer interrupted, etc.).

Categories