Comments (4)
I cannot this test on my own because I have no Unix socket server.
I searched for some examples and in those examples, they set the protocol type to IP instead of TCP.
So, I exposed the protocol type in the MQTTnet client options.
Could you please try version 4.3.4.1071 from the MyGet feed (https://www.myget.org/feed/mqttnet/package/nuget/MQTTnet) and let me know if changing the protocol type (to IP) fixes the issue?
from mqttnet.
I try to set protocol type to "IP" with the build 4.3.4.1071.
My code:
mqttClient = this.mqttFactory.CreateMqttClient();
var mqttClientOptions = new MqttClientOptions
{
ChannelOptions = new MqttClientTcpOptions
{
RemoteEndpoint = new UnixDomainSocketEndPoint("/tmp/mosquitto.sock"),
AddressFamily = AddressFamily.Unix,
ProtocolType = ProtocolType.IP
},
};
var response = await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
if (response.ResultCode == MqttClientConnectResultCode.Success)
{
Console.Write("CONNECTED TO MQTT BROKER !");
}
I don't have the same error but there is another one on the NoDelay property:
Unhandled exception. MQTTnet.Exceptions.MqttCommunicationException: Operation not supported
May 13 08:31:23 PWE HmiAPI[167]: ---> System.Net.Sockets.SocketException (95): Operation not supported
May 13 08:31:23 PWE HmiAPI[167]: at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName)
May 13 08:31:23 PWE HmiAPI[167]: at System.Net.Sockets.Socket.UpdateStatusAfterSocketOptionErrorAndThrowException(SocketError error, String callerName)
May 13 08:31:23 PWE HmiAPI[167]: at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue, Boolean silent)
May 13 08:31:23 PWE HmiAPI[167]: at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue)
May 13 08:31:23 PWE HmiAPI[167]: at MQTTnet.Implementations.CrossPlatformSocket.set_NoDelay(Boolean value)
May 13 08:31:23 PWE HmiAPI[167]: at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync(CancellationToken cancellationToken)
May 13 08:31:23 PWE HmiAPI[167]: at MQTTnet.Adapter.MqttChannelAdapter.<>c__DisplayClass30_0.<<ConnectAsync>b__1>d.MoveNext()
I searched more information about SocketOptionLevel, and it seems that it is not possible to set SocketOptionLevel.TCP or IP to an unix socket: https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socketoptionlevel?view=net-8.0
(I use socket with "Unix" addressFamily).
Update:
I rebuild the library on my own, and I commented 'set' method for NoDelay property in the file 'CrossPlatformSocket.cs':
public bool NoDelay
{
// We cannot use the _NoDelay_ property from the socket because there is an issue in .NET 4.5.2, 4.6.
// The decompiled code is: this.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Debug, value ? 1 : 0);
// Which is wrong because the "NoDelay" should be set and not "Debug".
get => false /*(int?)_socket.GetSocketOption(SocketOptionLevel.IP, SocketOptionName.NoDelay) != 0*/;
set { } /* _socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.NoDelay, value ? 1 : 0);*/
}
I know it is not a final solution, but it is only for testing.
Then, I set 'protocolType' to 'Unspecified' like that:
mqttClient = this.mqttFactory.CreateMqttClient();
var mqttClientOptions = new MqttClientOptions
{
ChannelOptions = new MqttClientTcpOptions
{
RemoteEndpoint = new UnixDomainSocketEndPoint("/tmp/mosquitto.sock"),
AddressFamily = AddressFamily.Unix,
ProtocolType = ProtocolType.Unspecified
},
};
var response = await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
if (response.ResultCode == MqttClientConnectResultCode.Success)
{
Console.Write("CONNECTED TO MQTT BROKER !");
}
With this change, it works !
from mqttnet.
Thanks for testing and providing feedback.
Please try again with version x.x.x.1073 from the myget feed. The NoDelay is only set if the protocol type supports that algorithm at all.
It if works I can create a PR, merge and release a new version.
from mqttnet.
I tried with the build x.x.x.1073 and it works !
I think you can merge, and thank you for your support 😃
from mqttnet.
Related Issues (20)
- MqttClient Publish a message when you are inside the `InterceptingPublishAsync` result to an Error when the Client Publish a QoS 1
- MqttServer messages send get lost while client is subscribing HOT 2
- Unable to use certificate in Ubuntu (TLS1.2) HOT 1
- MqttClient with TLS and client certificate works on Linux but not on windows using the latest and following samples HOT 18
- No valid replacement for the obsolete MqttClientOptionsBuilder.WithConnectionUri HOT 1
- MQTTnet.AspTestApp Fails to start HOT 1
- MQTTnet.Extensions.WebSocket4Net uses several outdated and possibly vulnerable dependencies HOT 3
- MQTT-over-Websocket connection reconnects every 30 seconds (MAUI regression) HOT 1
- Can't connect to broker using CA Cert ClientCert and Key HOT 2
- Last Will not working? HOT 2
- [FR] Protobuf HOT 3
- PublishAsync doesn't return a result nor exception HOT 4
- Linux - when Upgrading from version 4.3.3.952 to 4.3.4.1084 the client always raises the exception «None of the discovered or specified addresses match the socket address family» HOT 7
- Restore messages per client/subscription
- No connection could be made because the target machine actively refused it. HOT 1
- Breaking Change in MqttClientTcpOptions with 4.3.5.1141 HOT 3
- Managed MQTT client hangs when trying to disconnect using `StopAsync()` in Unity Engine HOT 3
- UWP PublishAsync forever hangs
- Event when pending ApplicationMessage was published
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttnet.