NS3 with MQTT integration. HELP !!!!

Hi, I'm doing my thesis on the NS3 environment. I need to integrate it with mqtt. Mqtt provides a (mosquitto) broker / server, and it expects to have clients connect to it. A client could be a publisher (publishes data on the broker) or a subscriber (receives data from the broker it has subscribed to).

SOOOO, i need to have an NS3 node as a publisher client. I have set everything working (Nodes, WiFi, TAP NET device etc) and i do have a connection made to the broker.

THE PROBLEM IS THAT: as soon as the connection is made, and the broker recognizes my NS3 node using my ID "publisher" , the connection is subsequently disconnected, so fast almost in a flash. Here is the output from the mosquitto broker:

1329401026: New connection from 191.13.13.2.
1329401026: New client connected from 191.13.13.2 as publisher.
1329401026: Socket read error on client publisher, disconnecting.

I have delved into the broker code and the error seems to be coming from the file: - loop.c in function 'loop_handle_reads_writes() at if(mqtt3_net_read(db, i)) line 267'
- or then from mosquitto.c after pselect() at point if(mqtt3_net_read(contexts[i]) line 280.

I DO NOT EXPLICITELY CLOSE my NS3 node socket after opening it. I am using an altered version of bulk-send-application.cc to include capability to also receive data from a server, and then i create a custom mosquitto namespace to add the mosquitto client functions which i will call from the bulk-send-applicaiton.cc.

WHY IS THE BROKER ACCEPTING MY CONNECTION, RECEIVES MY INFORMATION I SEND TO IT, SINCE IT DISPLAYS MY ID ('publisher'), THEN ALMOST IMMEDIATELY DISCONNECTS ME WITH A SOCKET-READ-ERROR WHILE I HAVE NOT EXPLICITELY CLOSED MY NS3 SOCKET ? :confused: :confused: :eek: :frowning: :wall: :wall:

Have you tried using one of the clients supplied with mosquitto? If they work then you know the problem is with your own client.

Yes, as i was learning the basics of mqtt, i did try out the mosquitto clients, publisher and subscriber and they worked. SO I KNOW ITS MY CLIENT.

That's why I need help!! Why is it that when i carry over the same client source code and make a (somewhat) application out of it for an NS3 Node, it fails?

Why is it that the socket appears closed to the broker immediately after sending some data over?, which means the broker reads from the socket the first time. Btway, before the broker issues the socket-read-error, the socket passes the socket-write test (in the fd testing loop). Why does the socket-read fail? What happens to the frieking NS3 socket ? (4give my french. its frustrating!) Why does it appear closed ?

ps. I am using Debian 6 on a virtual box. I don't know if this is relevant but hey, anything to stop the pain :frowning:

The most likely reason is that your client is not sending valid MQTT packets. In this case, mosquitto will disconnect you immediately.

i think so too. However, the broker does read the packet the first time, and retrieves the mosq->id field which is set to "publisher". That's why it gives the error:
Socket read error on client "publisher", disconnecting.

if the packet was not valid, do you think it would access the field 'id' in the struct mosq sent over in the packet?

previously, when i was sending completely invalid packets, it would give the error:
Socket read error on client null, disconnecting.

So, is my packet reeally invalid? or is there some other reason? :rolleyes:

1 Like