0

I am searching for a long time on net. But no use this is occasional problem;

here are false mosquitto.log

1677746403: New connection from x.x.x.x:53696 on port 21883.
1677746403: New connection from x.x.x.x:53698 on port 21883.
1677746403: New connection from x.x.x.x:53700 on port 21883.
1677746403: New connection from x.x.x.x:53702 on port 21883.
1677746403: New connection from x.x.x.x:53704 on port 21883.
1677746403: New connection from x.x.x.x:53706 on port 21883.
1677746403: New connection from x.x.x.x:53708 on port 21883.
1677746403: New connection from x.x.x.x:53710 on port 21883.
1677746403: New connection from x.x.x.x:53712 on port 21883.
1677746403: New connection from x.x.x.x:53714 on port 21883.
1677746403: New connection from x.x.x.x:53716 on port 21883.
1677746403: New connection from x.x.x.x:53718 on port 21883.
1677746403: New connection from x.x.x.x:53720 on port 21883.

this is correct situation

1676530842: New connection from x.x.x.x:56714 on port 21883.
1676530842: New client connected from x.x.x.x:56714 as rec8cee7f3492dbf85f7f483b04541283e (p2, c1, k30).
1676530842: Will message specified (7 bytes) (r0, q2).
1676530842:     willTopic
1676530842: Sending CONNACK to rec8cee7f3492dbf85f7f483b04541283e (0, 0)

this is my code

ck(mosquitto_lib_init(), "mosquitto_lib_init()");
    m_strId = id;

    m_strIp = ip;
    m_nPort = port;
    m_nKeepAlive = keepTime;
    if (username.size())
        set_name_pwd(username, pwd);

    m_mosq = mosquitto_new(NULL, true, NULL);
    mosquitto_connect_callback_set(m_mosq,on_connect);
    mosquitto_disconnect_callback_set(m_mosq,on_disconnect);
    mosquitto_publish_callback_set(m_mosq, on_publish);
    int rec = ck(mosquitto_connect_async(m_mosq,m_strIp.c_str(), m_nPort, m_nKeepAlive), "connect_async");

Thanks in advance

hardillb
  • 54,545
  • 11
  • 67
  • 105
Mike w
  • 1
  • 2
    Where is your call to `mosquitto_loop` or any of its variants? Without that mosquitto cannot process the reuslts of connecting etc. – Botje Mar 02 '23 at 10:22

1 Answers1

1

The connection log message is just that, it shows that something has opened the socket, not that anything has been sent over that open socket.

The New client connected message is printed when the broker receives a CONNECT packet from the client.

As pointed out in the comments, you need to start the mosquitto client network loop to ensure all the required packets are both sent and received/processed by the client.

hardillb
  • 54,545
  • 11
  • 67
  • 105