AnsweredAssumed Answered

MQX v4.2+RTCS simultaneous port connections

Question asked by Phil Roth on Feb 16, 2019
Latest reply on Feb 17, 2019 by Phil Roth

I have multiple threads of the function below and can only connect to 1 port at a time.  I'm testing this code by running Hyperterminal on a PC and simply connecting and disconnecting the port. Each port works, each thread works, but I must close the open port on Hyperterminal before I can connect to the other port and verse visa. I've read about a bunch of other ways to support multiple ports, using select( ) and scanning through a list of sockets, but I'd like to get this to work.


Not sure if I have something configured improperly with MQX or RTCS or I'm just doing something silly with my code. This same approach worked with Nucleus OS.


Again, not trying to get advice on how to do it differently unless what I'm trying ain't gonna work, just trying to figure out why this approach isn't working.


Any help appreciated....

Thank You




void tcp_task (uint32 channel)
    char         str[80];
    int         err;
    uint32      option;
    uint32         count;
    sockaddr    addr;
    uint32         listen_sock;
    uint32      client_sock;
    rtcs_fd_set rfds;
    CHANNEL_PTR p = com_ptrs[channel];


    /* Prepare socket for incoming connections */
    listen_sock = socket(PF_INET, SOCK_STREAM, 4);
    (void) setsockopt(listen_sock, SOL_TCP, OPT_TBSIZE, &option, sizeof(option));
    (void) setsockopt(listen_sock, SOL_TCP, OPT_RBSIZE, &option, sizeof(option));
    ((sockaddr_in*) &addr)->sin_family = AF_INET;
    ((sockaddr_in*) &addr)->sin_port = ports[channel-TCP1];
    ((sockaddr_in*) &addr)->sin_addr.s_addr = INADDR_ANY;
    bind(listen_sock, &addr, sizeof(addr));


    listen(listen_sock, 0);




    while(1) {
       /* Accept incoming connection */
        client_sock = accept(listen_sock, NULL, NULL);
        if(client_sock == RTCS_SOCKET_ERROR)


        /* Set socket option OPT_RECEIVE_NOWAIT = TRUE */
        option = TRUE;
        setsockopt(client_sock, SOL_TCP, OPT_RECEIVE_NOWAIT, &option, sizeof(option));


        status[channel] = CONNECTED;