Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket connection to 'ws:https://127.0.0.1:10086/' failed: #2021

Open
wolfcome110 opened this issue Jun 13, 2024 · 1 comment
Open

WebSocket connection to 'ws:https://127.0.0.1:10086/' failed: #2021

wolfcome110 opened this issue Jun 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@wolfcome110
Copy link

How to configure the mqtt server?

Steps to reproduce the behavior:

  1. Using this version of MQTTnet '4.3.6.1152'.
  2. Run this code '....'.
  3. See error:'mqtt.min.js:5 WebSocket connection to 'ws:https://127.0.0.1:10086/' failed: ',' Connection error:Error: WebSocket error'
  • Client
    ` var host = ‘127.0.0.1;
    var port = 10086;
    var path = ’‘;
    var clientID = ’123‘; //clientID
    var user = ’admin;
    var password = '123456';
    var url = host+':'+port+path;

    var options = {
    clientID:clientID,
    username:user,
    password:password
    };
    client = mqtt.connect(url,options);
    `

`builder.Services.AddHostedService<MqttHostService>();`

MqttHostService.cs
`
public Task StartAsync(CancellationToken cancellationToken)
{
    MqttServerOptionsBuilder optionsBuilder = new MqttServerOptionsBuilder();
    optionsBuilder.WithDefaultEndpoint();
    optionsBuilder.WithDefaultEndpointPort(10086); 
            
    optionsBuilder.WithConnectionBacklog(1000); 
    //optionsBuilder.AddWebSocketEndpoint("0.0.0.0", 9001);
    MqttServerOptions options = optionsBuilder.Build();
            
    MqttService._mqttServer = new MqttFactory().CreateMqttServer(options);

    MqttService._mqttServer.ClientConnectedAsync += _mqttServer_ClientConnectedAsync; 
    MqttService._mqttServer.ClientDisconnectedAsync += _mqttServer_ClientDisconnectedAsync; 
    MqttService._mqttServer.ApplicationMessageNotConsumedAsync += _mqttServer_ApplicationMessageNotConsumedAsync; 

    MqttService._mqttServer.ClientSubscribedTopicAsync += _mqttServer_ClientSubscribedTopicAsync;
    MqttService._mqttServer.ClientUnsubscribedTopicAsync += _mqttServer_ClientUnsubscribedTopicAsync; 
    MqttService._mqttServer.StartedAsync += _mqttServer_StartedAsync; 
    MqttService._mqttServer.StoppedAsync += _mqttServer_StoppedAsync; 
    MqttService._mqttServer.InterceptingPublishAsync += _mqttServer_InterceptingPublishAsync; 
    MqttService._mqttServer.ValidatingConnectionAsync += _mqttServer_ValidatingConnectionAsync; 

    MqttService._mqttServer.StartAsync();
    return Task.CompletedTask;
}
`
@wolfcome110 wolfcome110 added the bug Something isn't working label Jun 13, 2024
@mimimiaomiao1
Copy link

我也连不上。。我的前端是vue,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants