mqtt_Connect() Socket error?

I’m developing a SW to connect with mosquitto broker. I started from the source code in apps/platformservices of Legato environment.
I can right build the project, create the session, but I have problem when I have to connect to the broker:
I’m trying to connect without user and password (I’m beginning!) and this is the result:

Obviously I connected my mangOH green to internet thought both WiFi and Sim and I can righly ping google, so it is not a connection trouble. Mosquitto is running on my VM:

Can someone help me to understand the cause of this problem? Here is the code I’m working on…
maqqClientServicee.txt (36.7 KB)
Which could be the problem?

No one can help me? Is there a guide to install a broker on a VM? Have I to configure a file mosquitto.conf (if mosquitto is a broker)? I’m desperate, I can’t make mqtt app available after a month spent on this so difficult HW

Try connecting using nc first.

nc localhost 1883 // fake client try to connect to local broker
nc -l localhost 1883 // fake broker try to connect from client

It might show you where the problem is.

Hi @piinst. First of all thank you a lot for the attention. Do you mean it?
Indeed my mangOH does not seem to connect to the Broker. Could be the cause of the problem here?

In Ubuntu host I see it:

Well close. My example was client and broker on same system.

If your broker was on Ubuntu and you want to test connectivity from WPxxxx you should ssh into root@ and then

nc 1883

If you connect that means you are getting through to the broker. Nothing will happen after the connect.

Nothing happens…so my mangOH is seeing mqtt broker right?

Looks that way. See the following:

root@swi-mdm9x28-wp:~# nc 7777
nc: can't connect to remote host ( Connection refused
root@swi-mdm9x28-wp:~# nc 1883

The first attempt uses a bad port number 7777 so it’s refused. The second attempt connects. This indicates that your broker on Ubuntu is OK to receive connections from the WPxxxx.

This means that if your application on the WPxxxx won’t connect to the broker on Ubuntu it is probably doing something wrong.

Okay…so this is a SW issue (also if I don’t understand what!). Thanks a lot @piinst , at least now I know what to focus on.
Unfortunately this is the result and I really don’t understand the cause:

If you stop the MQTT broker on Ubuntu and start it again with tracing you might be able to get some information.

paul@paul-ThinkCentre-M72e:~$ sudo systemctl stop snap.mosquitto.mosquitto.service
paul@paul-ThinkCentre-M72e:~$ /snap/mosquitto/current/usr/sbin/mosquitto -v -c /snap/mosquitto/current/default_config.conf
1619813633: mosquitto version 1.6.14 starting
1619813633: Config loaded from /snap/mosquitto/current/default_config.conf.
1619813633: Opening ipv4 listen socket on port 1883.
1619813633: Opening ipv6 listen socket on port 1883.
1619813633: mosquitto version 1.6.14 running

okay @piinst it seems that I have correctly installed Mosquitto and that it is running on 1883

Maybe could be the problem the version of mosquitto? I have the last one…

maybe I understand the problem!
On Raspberry PI forum I see:

So I have two options:
1. I install a previous version of Mosquitto (for example 1.6.14)…but I can’t understand how, since sudo apt-get install mosquitto option gives the last version automatically !
2. I install the last version of Mosquitto (2.0.10) but giving the commands listener 1883
allow_anonymous true…but I can’t understand how and where!

Do you think that my reasoning is good or am I out of road?

Okay, I modified the config file:

I see it, so I think that mosquitto is in listening, right?

But the socket error doesn’t disappear :pensive:

no one can help me on socket error? I can’t find a solution. I’m desperate, guys

It appears that the client is getting an error before mosquitto receives anything. Best thing to do in my view is look at the source for a client such as MQTTClient_publish.c and see how it works.

I tried, but unfortunately this is not the solution either. However, I noticed another thing. I have Mosquitto server installed on windows of another PC and from my Ubuntu I can ping (seeing the connection attempt on the other side):
But if I repeat the same operation from my mangOH nothing happens:
It’s a normal thing? Should my mangOH be configured on a door? Because at this point it’s really not clear to me what I’m wrong

Problem solved: using MOSQUITTO MQTT client and server must be on the same wlan. I dodn’t know it. Thank you all for the support