Can't connect from blazor WASM using WebSocket and TLS #1464
Unanswered
FabrizioSalis
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Please provide some more details which kind of error you get. Please try to connect using MQTTnetApp (https://github.com/chkr1011/MQTTnetApp) and let me know if it work for that app. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I tried with your console, and same error. Here you have all the SERVER source code: In the attachments, the client configuration. using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using MQTTnet.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
var certificate = new X509Certificate(@"D:\cert.pfx", "******", X509KeyStorageFlags.Exportable);
builder.Services.AddHostedMqttServer(options =>
{
options.WithEncryptedEndpointPort(1883);
options.WithEncryptedEndpoint();
options.WithRemoteCertificateValidationCallback((sender, certificate, chain, errors) => true);
options.WithEncryptionCertificate(certificate.Export(X509ContentType.Pfx));
options.WithTlsEndpointReuseAddress();
options.WithEncryptionSslProtocol(SslProtocols.Tls12);
});
builder.Services.AddMqttTcpServerAdapter();
builder.Services.AddMqttWebSocketServerAdapter();
builder.Services.AddMqttConnectionHandler();
builder.Services.AddConnections();
builder.WebHost.ConfigureKestrel(o =>
{
o.ListenAnyIP(1883, l => l.UseMqtt());
o.ListenAnyIP(5000);
});
var app = builder.Build();
app.MapGet("/", () => "The MQTT Service is running.");
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapConnectionHandler<MqttConnectionHandler>("/mqtt",
httpConnectionDispatcherOptions => httpConnectionDispatcherOptions.WebSockets.SubProtocolSelector =
protocolList => protocolList.FirstOrDefault() ?? string.Empty);
});
app.Run(); and this is the exception from the test app:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
I am trying to connect from a blazor WASM application to a cloud hosted MQTT server.
The only way to communicate is by the usage of WebSockets, because TCP access is denied from a browser.
Another requirement is to use TLS encryption.
This is my client configuration:
and this is the server part:
I got an error during the handshake. I guess something is missing in the server configuration, maybe I should set a certificate somewhere?
Thanks for your help
Beta Was this translation helpful? Give feedback.
All reactions