Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

UDP vs TCP on esp32

Hi,

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?

Comments

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

    port_ = port;
    std::stringstream ss;
    ss << "udp://255.255.255.255:" << 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:
    break;
    case MG_EV_ACCEPT:
    break;
    case MG_EV_CONNECT:
    break;
    case MG_EV_SEND:
    break;
    case MG_EV_RECV:
    mbuf_remove(io, io->len); // Discard data from recv buffer
    break;

        case MG_EV_CLOSE:
            udp_data_endpoint->close();
            break;
        default:
            break;
        }
    }
    
  • 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.