Advanced Users can post their questions and comments here for the not so Newbie crowd.

Moderator: eriksl

User avatar
By maverickchongo
#82387 Hi,

When I create a second UDP connection with:

espconn_create(struct espconn *espconn)

Both connecions with all the remote and local data (ports and IPs) different, the data of the first connection is overwritten by the second one.

Has anybody experience this?
User avatar
By maverickchongo
#82397 Here you go:

CREATION OF CONNECTOR 1
Code: Select all     struct espconn udp_mdns_connector;

    //setup UDP the connector
    os_memset(&udp_mdns_connector, 0, sizeof(udp_mdns_connector));
    udp_mdns_connector.type = ESPCONN_UDP;
    udp_mdns_connector.state = ESPCONN_NONE;
    udp_mdns_connector.proto.udp = &udp_con;

    os_memset(&udp_con, 0, sizeof(udp_con));

    udp_con.local_ip[0] = ip4_addr1(&stationIp.ip);
    udp_con.local_ip[1] = ip4_addr2(&stationIp.ip);
    udp_con.local_ip[2] = ip4_addr3(&stationIp.ip);
    udp_con.local_ip[3] = ip4_addr4(&stationIp.ip);

    /*set mdns multicast ip addr*/
    os_memcpy(udp_con.remote_ip, mdns_multicastIp, sizeof(mdns_multicastIp));

    udp_con.local_port = MDNS_PORT;
    udp_con.remote_port = MDNS_PORT;

    /* set data callback for when data has been sent/received */
    espconn_regist_recvcb(&udp_mdns_connector, &_mdns_response_received);
    espconn_regist_sentcb(&udp_mdns_connector, &_mdns_dataSent);

    /* create udp connector */
    err = espconn_create(&udp_mdns_connector);


CREATION OF CONNECTOR 2:
Code: Select all    struct espconn connector;
    //Connect and send some data
    os_memset( &connector, 0, sizeof(connector));
    connector.type = ESPCONN_UDP;
    connector.state = ESPCONN_NONE;
    connector.proto.udp = &udp_con;
   
    os_memset( &udp_con, 0, sizeof(udp_con));
    wifi_get_ip_info( STATION_IF, &stationIp );
   
    udp_con.local_ip[0] = ip4_addr1(&stationIp.ip);
    udp_con.local_ip[1] = ip4_addr2(&stationIp.ip);
    udp_con.local_ip[2] = ip4_addr3(&stationIp.ip);
    udp_con.local_ip[3] = ip4_addr4(&stationIp.ip);
    udp_con.local_port = 8181;

    udp_con.remote_port = rdp_serverPort;
    os_memcpy ( udp_con.remote_ip, rdp_serverIp, 4 );

    // set some data callbacks
    espconn_regist_recvcb( &connector, &rdp_dataReceived );
    espconn_regist_sentcb( &connector, &rdp_dataSent );
   
    err = espconn_create ( &connector );
Last edited by maverickchongo on Tue May 21, 2019 5:51 am, edited 1 time in total.
User avatar
By davydnorris
#82403 Are you setting the connection type somewhere? Something like
Code: Select alludp_con.type = ESPCONN_UDP;


Also UDP is different to TCP - you need to set the remote ip and port before every single send call, otherwise it remembers the last info. See:
http://controllingtheinter.net/2018/06/04/resolving-udp-and-igmp-issue-with-esp8266/

"If it is a UDP transmission, please set espconn->proto.udp->remote_ip and remote_port before every calling of espconn_send."