WebSocket connection to 'ws://127.0.0.1:10086/' failed:
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
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://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);
`
```csharp
`builder.Services.AddHostedService();`
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;
}
`
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with MqttHostService.cs and compare the mqtt.min.js WebSocket URL with the server setup, especially the commented AddWebSocketEndpoint call. Verify which endpoint the server starts on and confirm that a WebSocket client can connect successfully to the configured address and port.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, javascript
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100