Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

UDP vs TCP on esp32


I am using mongoose socket/networking library. I do get UDP disconnect event when I join station/client Access point and UDP stop working on my own Access point and if I reconnect UDP port programmatic after gotIP address event. or restart device then It starts working for station/client Access point UDP behaviour is different from TCP. TCP still working for both its own Access Point and station Access point after station access point join.

Any idea?

Any workaround?


  • For UDP connection at server. I get MG_EV_CLOSE event.

    port_ = port;
    std::stringstream ss;
    ss << "udp://" << port_;

    struct mg_connect_opts opts_connect;

    memset(&opts_connect, 0, sizeof(opts_connect));
    opts_connect.flags = MG_F_ENABLE_BROADCAST;
    opts_connect.iface = nullptr;
    struct mg_bind_opts opts;
    memset(&opts, 0, sizeof(opts));
    opts.flags = MG_F_ENABLE_BROADCAST;
    opts.iface = nullptr;
    // Note that many connections can be added to a single event manager
    // Connections can be created at any point, e.g. in event handler function
    // Create listening connection and add it to the event manager
    server_connection_->nc_ = mg_connect_opt(&mgr_, ss.str().c_str(), udp_endpoint_ev_handler, opts_connect);
    //connection_->nc_ = mg_bind_opt(&mgr_mgr_->mgr_, ss.str().c_str(), udp_endpoint_ev_handler, opts);

    static void udp_endpoint_ev_handler(struct mg_connection *nc, int ev, void *ev_data)
    struct mbuf *io = &nc->recv_mbuf;
    switch (ev) {
    case MG_EV_POLL:
    case MG_EV_ACCEPT:
    case MG_EV_CONNECT:
    case MG_EV_SEND:
    case MG_EV_RECV:
    mbuf_remove(io, io->len); // Discard data from recv buffer

        case MG_EV_CLOSE:
  • Should I used mg_connect_opt or mg_bind_opt for setup UDP server to send broadcast messages.

    I tried only mg_connect_opt works for me. but it allow only one udp client to connect to receive messages. multiple udp clients can connect to receive these messages?

Sign In or Register to comment.