Giter Site home page Giter Site logo

Comments (4)

chkr1011 avatar chkr1011 commented on May 24, 2024

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.

BastienCUENOT avatar BastienCUENOT commented on May 24, 2024

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.

chkr1011 avatar chkr1011 commented on May 24, 2024

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.

BastienCUENOT avatar BastienCUENOT commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.