I have a digital a digital ocean droplet ubuntu with docker installed. I installed Typesense container which is running healthy.
if I write curl http://127.0.0.1:8108/health or curl http://localhost:8108/health or curl http://171.122.255.261:8108/health in the command line of my droplet I get
{"ok":true}
171.122.255.261 is the public address of my droplet (fake ip)
So Typesense container is mapped on 8108:8108.
When I try to connect to Typesense via my Dart code I do it like:
class MyTypesense with UsersTypesenseQueries {
@override
late final Client client;
MyTypesense() {
final config = Configuration(
'xyz',
nodes: {
Node.withUri(
Uri(
scheme: 'http',
host: '171.122.255.261',
port: 8108,
),
),
},
numRetries: 3, // A total of 4 tries (1 original try + 3 retries)
connectionTimeout: const Duration(seconds: 15),
);
client = Client(config);
}
}
This works when I connect to my droplet's typesense via other machines.
But then, if I try to run dart code inside my droplet and connect to typsense like this (it doesnt work):
class TypesenseDatabase { late final Client client;
TypesenseDatabase() {
final config = Configuration(
'xyz',
nodes: {
Node.withUri(
Uri(
scheme: 'http',
host: '127.0.0.1',
port: 8108,
),
),
},
numRetries: 3, // A total of 4 tries (1 original try + 3 retries)
connectionTimeout: const Duration(seconds: 2),
);
client = Client(config);
}
}
I have tried changing host to localhost, to droplets public address and nothing seems to work. I get this logs
"ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 44250, uri=http://127.0.0.1:8108/collections?"
I dont understand why port = 44250. but everytime I try to run it the port changes. Per example here is another log after I run it again:
"ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 44408, uri=http://127.0.0.1:8108/collections?"
What am I missing?
In summary:
I can connect with typesense which is installed in my droplet in a docker container whenever I connect with other machines. But once I try to connect inside the droplet (locally) I cannot