Flutter, can't connect/remote to MariaDB database from android - flutter

I'm using the mysql1 package to connect to MariaDB.10 database using (MariaDB4j)
Issue:
1- it connects if I test the Flutter app on Windows but does not work if I test it on a real android phone.
I got this error:
I/flutter ( 3337): SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 192.198.1.108, port = 53416
The code: port is 3306 as you can see above on the error message the port keeps changing, and I'm connecting the IP of the phone on the local network.
var settings = ConnectionSettings(
host: _host,
port: int.parse(_port),
user: 'root',
password: "",
db: 'distoresql');
conn = await MySqlConnection.connect(settings);
Note: I have added a user to the Mysql user with the phone IP and GRANT ALL PRIVILEGES to this user and IP, and I have disabled security on the connection.

Related

How to check server ip is blocked and tell to use VPN in flutter?

I got following crash report in firebase crashlytic. Even thought, I use Connectivity WrapperIt is still throw a lot. The country most of the user used in is blocking the ip. They only open for selected app. There are a lot of ISP and some are blocked our ip and some are not. For example, they blocked facebook. How can I check and tell the user need to open VPN to use this app.
SocketException: Failed host lookup: 'fileapi.domain.org' (OS
Error: No address associated with hostname, errno = 7). Error thrown
Instance of 'ErrorDescription'.
SocketException: Connection reset by
peer (OS Error: Connection reset by peer, errno = 104), address =
fileapi.domain.org, port = 36536.
SocketException: Software
caused connection abort (OS Error: Software caused connection abort,
errno = 103), address = fileapi.domain.org, port = 49644.
Connection closed before full header was received. HandshakeException:
Connection terminated during handshake.

Unhandled Exception: SocketException: Failed host lookup: 'imap.gmail.com' (OS Error: No address associated with hostname, errno = 7)

I was used imap_client package in my app to read my mail.
below is my connection code:
`ImapClient client = new ImapClient();
await client.connect("imap.gmail.com", 993, true);
print("success");`
Looks like your are not connected to internet. Or maybe the server you are using is temporarily down. Mainly there are the causes behind Socket Exception.

Flutter / Dart Error SocketException: OS Error: The remote computer refused the network connection. , errno = 1225, address = 127.0.0.1, port = 59250

I am getting this error in my debugger.
From what I understood it's an error generated by ip config.
I found this solve here, but i dont understand where should i modify it. where should i change the ip address?
Flutter SocketException (SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 51500)
ERROR - 2021-03-23 18:21:26.074284
PUT /SXUs66yGd7s=/
Error thrown by handler.
SocketException: OS Error: The remote computer refused the network connection.
, errno = 1225, address = 127.0.0.1, port = 59250
Help!
Thank you alot
I was going through this trouble myself
i just disconnect the emulator and restated
Not sure what is your environment:
for me->
I tried to run windows app with xampp localhost and received this error.
then i changed my uri in frontend to
String uri = 'http://127.0.0.1/db-name';
after that, all working.
in the emulator the uri is different.
String uri = 'http://your ip addres/db-name';
to get your ip address->
open cmd and run "ipconfig"
use ipv4.

How to resolve - SocketException: Failed host lookup: 'server.com' (OS Error: nodename nor servname provided, or not known, errno = 8)

I am pretty new to flutter development. I am getting the following error on connecting to the server:
SocketException: Failed host lookup: 'server.com' (OS Error: nodename nor servname provided, or not known, errno = 8)
I already referred the below link, but this was of no help for me
How to solve SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)
Currently I am testing my application on iOS simulator. Below are the versions I am using,
Http version - http: ^0.12.2
Flutter version - 1.22.4(Stable version)
The server is connecting when I am using mobile hotspot with my company's VPN enabled. But, I get this error when I switch to the company LAN.
All the APIs are working fine in postman when connected to LAN. I am using Android Studio. Is there any specific configuration to be made in flutter? Please let me know...
Internet is off or signal is not strong. Check your LAN connection.

no pg_hba.conf entry for host / Connect call failed / Invalid data directory for cluster 12 main - Postgresql Ubuntu

I'm trying to move my bot to an Ubuntu virtual server from Vultr but it's having a problem connecting to the postgres database. I've tried editing the config from md5 to true, and host to local, etc. But those only give me different errors and also make it stop working on my original machine too. It's working perfectly fine on my Windows machine. Here is the error I'm facing:
asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host "[local]", user "postgres", database "xxx", SSL off
So I've tried to change this line:
async def create_db_pool():
bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???')
to this:
async def create_db_pool():
bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???', ssl=True)
and that gives me this error:
asyncpg.exceptions._base.InterfaceError: `ssl` parameter can only be enabled for TCP addresses, got a UNIX socket path: '/run/postgresql/.s.PGSQL.5432'
So I don't know what else to try. I've been stuck on this for a while. If it's relevant, it connects at the bottom of the bot.py file like this:
bot.loop.run_until_complete(create_db_pool())
Whether ssl is True or not, the database seems to still function on my Windows machine. But I can't get it to work on my Ubuntu virtual server.
If I edit my config to this:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::/0 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 0.0.0.0/0 md5
host replication all ::/0 md5
Then I get a call error like this:
OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 5432, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 5432)
This is really driving me crazy. I have no idea what to do. I bought this virtual server to host my bot on but I can't even get it to connect to the database.
When I simply type psql in the terminal, I get this error:
Error: Invalid data directory for cluster 12 main
Postgres is not working as intended in basically any way. I'm using Vultr.com to host the Ubuntu server, if that matters. And connecting with PuTTy.
Your pg_hba.conf has multiple syntax errors. The "localhost" connection type is not allowed at all, and the "local" connection type does not accept an IP address field. The server would refuse to start/restart with the file you show, and if you try to reload a running server it will just keep using the previous settings.
LOG: invalid connection type "localhost"
CONTEXT: line 4 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid authentication method "127.0.0.1/32"
CONTEXT: line 5 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid authentication method "::1/128"
CONTEXT: line 9 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid connection type "localhost"
CONTEXT: line 10 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid authentication method "127.0.0.1/32"
CONTEXT: line 102 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
FATAL: could not load pg_hba.conf
LOG: database system is shut down