Appwrite with Flutter [Connection refused] - flutter-dependencies

I just tried appwrite platform for Flutter, but this happened after any request I tried.
The server is initialized at http://localhost:300 (or https://localhost:301), endpoint = http://localhost:300/v1
static Future<void> init() async {
_client = Client();
_client.setEndpoint("http://localhost:300/v1").setProject('5fccf1924cbf5').setSelfSigned();
_db = Database(_client);
}
E/flutter (28886): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 47194
E/flutter (28886): #0 DioMixin._request._errorInterceptorWrapper.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:dio/src/dio.dart:870:17)
Only tried on Android (physical device) for now.

This is a network error. You should set your private IP instead of localhost as the Appwrite hostname in your Appwrite SDK client or use a service like ngrok to proxy the Appwrite API.
When trying to connect from an emulator or a device localhost is the hostname for the device or emulator.
Another good method to test that you're using the correct hostname is to check if you can access the Appwrite console from your device/emulator browser.

Related

MQTTNet with MQTT.js are not working together

I'm trying to use MQTTNet as service broker, that takes requests from webClients over MQTT.js. However, this method is notworking for unknown reasons.
when i test the Service Broker using the windows application "MQTT Explorer" as a client, it works fine.
When i test the MQTT.js Client to connect to an open Service Broker like broker.emqx.io it works also fine.
but the connection between my service Broker with the mqtt client has always a problem. The following error is thrown from the MQTTNet Server:
Client '[::1]:58434' accepted by TCP listener '[::]:8883, ipv6'.
Expected at least 21538 bytes but there are only 69 bytes
MQTTnet.Exceptions.MqttProtocolViolationException: Expected at least 21538 bytes but there are
only 69 bytes
at MQTTnet.Formatter.MqttBufferReader.ReadString()
at MQTTnet.Formatter.MqttPacketFormatterAdapter.ParseProtocolVersion(ReceivedMqttPacket
receivedMqttPacket)
at MQTTnet.Formatter.MqttPacketFormatterAdapter.DetectProtocolVersion(ReceivedMqttPacket
receivedMqttPacket)
at MQTTnet.Adapter.MqttChannelAdapter.ReceivePacketAsync(CancellationToken cancellationToken)
at MQTTnet.Server.MqttClientSessionsManager.ReceiveConnectPacket(IMqttChannelAdapter
channelAdapter, CancellationToken cancellationToken)
at MQTTnet.Server.MqttClientSessionsManager.HandleClientConnectionAsync(IMqttChannelAdapter
channelAdapter, CancellationToken cancellationToken)
Client '[::1]:58434' disconnected at TCP listener '[::]:8883, ipv6'.
configuration of my server are as following:
static async Task<MqttServer> StartMqttServer(bool isDevelopment, ConsoleLogger consoleLogger = null)
{
MqttFactory mqttFactory = new MqttFactory();
if (consoleLogger != null)
{
mqttFactory = new MqttFactory(consoleLogger);
}
// Due to security reasons the "default" endpoint (which is unencrypted) is not enabled by default!
var mqttServerOptions = mqttFactory.CreateServerOptionsBuilder()
.WithDefaultEndpoint()
.Build();
var server = mqttFactory.CreateMqttServer(mqttServerOptions);
await server.StartAsync();
return server;
}
does anybody know why is this happening? And perhaps have an idea how i can fix it?
Thanks in advaced.

Android Emulator with Localhost ASP.Net Core API Calls

I've been trying to perform a GET request from Visual Studio's Android Emulator to an ASP.Net Core API running on localhost. I first read that I have to use IP 10.0.2.2 when performing the request from Android, so I have the following HTTP client code in my Android (Xamarin) App
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
var logInbutton = FindViewById<Button>(Resource.Id.logInButton);
logInbutton.Click += OnLogInButtonClicked;
}
private async void OnLogInButtonClicked(object sender, EventArgs e)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var uri = new Uri("http://10.0.2.2:5555/api/Orders?api-version=0.9");
var response = await client.GetAsync(uri);
}
}
However, each time I attempt to run this I'm greeted with a 400 Bad Request error. I know the request is okay since I can run the same Http client code from a console app without any errors. I then read that IIS express does not accept external requests and since the Android emulator is running in a VM this could be the reason.
So I then followed the advice on this SO post but was greeted with an Invalid URI: The hostname could not be parsed error. I'm not sure how to proceed from here. Is there a solution to the Invalid URI: The hostname could not be parsed error, or should I attempt to circumvent IIS Express and run solely with kestrel for development? Would even running solely in kestrel fix this problem?
I had a similar issue.
First, let's locate the correct applicationhost.config file.
You should check this location:
[solution folder]/.vs/config/applicationhost.config
Then people advice to set up binding like this:
<binding protocol="http" bindingInformation="*:5555:*" />
It did NOT work for me. I received "Invalid URI: The hostname could not be parsed".
What did work for me is the syntax like this:
<binding protocol="http" bindingInformation=":5555:" />
Please note, port 5555 is given as example. You should use the port your server is listening to.
I ran into the same issue when attempting to connect while running through kestrel. For me it worked using this configuration for the launchsettings:

FCM/GCM App Server cannot connect to FCM/GCM CCS using SSLSocket and SMACK library

I'm writing a Firebase Cloud Messaing (FCM) App server program, and encountered a connection problem when I try to connect to FCM server via XMPP connection, using SMACK library. The program fails to be connected to the FCM server (fcm-xmpp.googleapis.com:5236).
Following an example,
https://github.com/carlosCharz/fcmxmppserverv2/blob/master/src/main/java/com/wedevol/xmpp/server/CcsClient.java,
I try to connect to the FCM server using SSL socket. The source codes are as follows.
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder ();
configBuilder.setUsernameAndPassword (senderId, serverKey);
configBuilder.setServiceName (CCMServiceName);
configBuilder.setHost (CCMServer);
configBuilder.setPort (CCMServerPort);
configBuilder.setSocketFactory (SSLSocketFactory.getDefault ());
configBuilder.setSecurityMode (SecurityMode.ifpossible);
configBuilder.setSendPresence (true);
configBuilder.setDebuggerEnabled(true);
SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
//Step 2. Generate a connection resource with CCM Server
connection = new XMPPTCPConnection (configBuilder.build ());
//Step 3. Connect
try {
systemLogStream.println ("Try to connect XMPP end-point: " + CCMServer );
connection.connect();
} catch (SmackException smackEx) {
systemLogStream.println ("SMACK Exception: " + smackEx.getMessage());
System.exit(999);
} catch (XMPPException xmppEx) {
systemLogStream.println ("XMPP Exception: ");
} catch (IOException ioEx) {
systemLogStream.println ("IO Exception: ");
}
However, it always fails to connect to FCM server generating following exception.
SMACK Exception: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.
To figure out the reason, I captured tcpdumps and it looks like SSLSocket does not send Clienthello message which is the first step to TLS handshake. Following is the result from Wireshark.
Wireshark capture result
I hope that someone nice gives a comment or an advise how to resolve this problem.
Thank you.

Paho Rabitmqq connection getting failed

Here is my paho client code
// Create a client instance
client = new Paho.MQTT.Client('127.0.0.1', 1883, "clientId");
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("/World");
message = new Paho.MQTT.Message("Hello");
message.destinationName = "/World";
client.send(message);
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
}
On Rabbitmq server everything is default seetings. When i run this code i get WebSocket connection to 'ws://127.0.0.1:1883/mqtt' failed: Connection closed before receiving a handshake response
What i am missing ?
From my personal experience with Paho MQTT JavaScript library and RabbitMQ broker on windows, here is a list of things that you need to do to be able to use MQTT from JS from within a browser:
Install rabbitmq_web_mqtt plugin (you may find latest binary here, copy it to "c:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.2\plugins\", and enable from command line using "rabbitmq-plugins enable rabbitmq_web_mqtt".
Of course, MQTT plugin also needs to be enabled on broker
For me, client was not working with version 3.6.1 of RabbitMQ, while it works fine with version 3.6.2 (Windows)
Port to be used for connections is 15675, NOT 1883!
Make sure to specify all 4 parameters when making instance of Paho.MQTT.Client. In case when you omit one, you get websocket connection error which may be quite misleading.
Finally, here is a code snippet which I tested and works perfectly (just makes connection):
client = new Paho.MQTT.Client("localhost", 15675, "/ws", "client-1");
//set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
//connect the client
client.connect({
onSuccess : onConnect
});
//called when the client connects
function onConnect() {
console.log("Connected");
}
//called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:" + responseObject.errorMessage);
}
}
//called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:" + message.payloadString);
}
It's not clear in the question but I assume you are running the code above in a web browser.
This will be making a MQTT connection over Websockets (as shown in the error). This is different from a native MQTT over TCP connection.
The default pure MQTT port if 1883, Websocket support is likely to be on a different port.
You will need to configure RabbitMQ to accept MQTT over Websockets as well as pure MQTT, this pull request for RabbitMQ seams to talk about adding this capability. It mentions that this capability was only added in version 3.6.x and that the documentaion is still outstanding (as of 9th Feb 2016)

Establishing a SignalR connection when using a self-signed certificate

I have a self-hosted WebAPI web service using a self-signed certificate. I am successfully able to communicate with the web service controller actions from other applications using the URL:
https://localhost:5150/...
Note that I have successfully bound the self-signed certificate to port 5150 and reserved the port for all IPs for my application, both by using the appropriate netsh commands.
I am trying to integrate a SignalR hub into this web service. I configure the hub, with CORS support, using the following in my startup code:
// Configure the SignalR hub that will talk to the browser
appBuilder.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
HubConfiguration hubConfig = new HubConfiguration();
hubConfig.EnableDetailedErrors = true;
hubConfig.EnableJavaScriptProxies = false;
map.RunSignalR(hubConfig);
});
I am starting up my HTTP listener, which is/was also used for Web API by this:
_webApp = WebApp.Start<Startup>(baseUrl);
where the baseUrl is
https://+:5150/.
My SignalR initialization code, in my Angular controller is:
var initialize = function () {
//Getting the connection object
connection = $.hubConnection("/signalr", { useDefaultPath: false });
// Url signalr scripts should hit back on the server
connection.url = ENV.SIGNALR.protocol + '://' + ENV.SIGNALR.server + ':' + ENV.SIGNALR.port + '/' + ENV.SIGNALR.url;
// Turn on client-side logging
connection.logging = ENV.SIGNALR.logging;
// Get proxy based on Hub name (must be camel-case)
proxy = connection.createHubProxy('dashboardHub');
// Setup event handlers for messages we get from the server.
proxy.on('rxDiagnosticMessage', function (msg) {
//console.log('Received rxDiagnosticMessage');
$rootScope.$broadcast("rx-diagnostic-message", msg);
});
//Starting connection
connection.start()
.done(function () { console.log('SignalR connection started'); })
.fail(function (err) { console.log('SignalR connection failed - ' + err); });
// Display errors to console
connection.error(function (err) {
console.log('SignalR error - ' + err);
});
};
When the connection to the hub is attempted, I get the following error:
15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Auto detected cross domain url. jquery.signalR-2.1.0.js:81
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'dashboardhub'. jquery.signalR-2.1.0.js:81
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with 'https://localhost:5150/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22dashboardhub%22%7D%5D'. jquery.signalR-2.1.0.js:81
GET https://localhost:5150/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22dashboardhub%22%7D%5D&_=1407524683014 net::ERR_INSECURE_RESPONSE jquery-2.1.1.js:8623
SignalR error - Error: Error during negotiation request. AppSignalR.js:43
SignalR connection failed - Error: Error during negotiation request. AppSignalR.js:39
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Stopping connection.
Note the net::ERR_INSECURE_RESPONSE during the SignalR connection negotiation.
Strange thing...if I run Fiddler2 then the connection works! (Is Fiddler serving up a nice certificate to my web app / SignalR?)
I suspect this is due to the certificate being self-signed (cert in Personal, cert authority in Trusted). In WCF and WebAPI clients I always intercept the authority errors and bypass the error:
ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
Is there something similar that needs to be done in the SignalR client in my Angular application? Or should this just work?
Note that I have seen this thread - SignalR with Self-Signed SSL and Self-Host still does not work for me.
You cannot use localhost with SSL, you need absolute HostName in URL.
Look at the ISSUED BY and ISSUED TO field in the Certificate you created, ISSUED BY needs to be part of the "Trusted Publisher" list on your machine(machine that is accessing the webpage using browser), and ISSUED TO needs to be part of your URL .i.e. the certificate has been issued to you and only you. So if your ISSUED TO field has value "HOSTNAME.DOMAINNAME" where HOSTNAMe is hostName of the machine and DomainName is the Domain of the machine where the web site is hosted, then you need to access your SITE using the same name i.e
.
Hope this helps.