This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: TCP server connection timeout

Part Number: TM4C1294NCPDT


Hi,

I made MCU as a tcp client and it works fine with server . only thing is that connect function takes time to connect with server, I need to reduce that time. I am attaching a snippet of code where connect function is meant for connecting to server. it takes time to revert with response code.

    while(connect(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0)
    {
        lcd_put_cur(1, 0);
        lcd_send_string("Server Not Ready");
        SysCtlDelay(g_ui32SysClock);
        if(LC_RMT_PIN)
        {
            MODE=LOCAL;
            goto Local;
        }
        lcd_put_cur(1, 0);
        lcd_send_string("Waiting...      ");
    }

Regards

Khodidas

  • Hi,

      I don't really see an issue with your snippet. Normally, you will create a socket, setup the server IP address and port and connect to the server using the connect() like the example below which is the same as yours. 

    status = connect(clientfd, (struct sockaddr *) &servAddr, sizeof(servAddr));

      How long of the wait are we talking about? Does it make a difference if you run your client program on a different network? For example, run it on your home network. Is the connection time still very long? If the connection varies depending on the network in which you operate then you will need to check your network or your IT support can help you. 

      There are some client examples in this app note. https://www.ti.com/lit/pdf/spma080. If you run the example, will it have long connection time? When I run it, the connection time is reasonable. If you experience the same long connection time then it may have something to do with your network and I can't really help you on that. 

      

  • Hi Chrles,

    Sorry for Delay due to Holidays, I have direct connection with my PC, and not routing through any network. I have written application in a way that, if server is not running then client will try to connect and timeout in connect function. so it is taking approx 3 minutes, that i need to reduce. 

    Regards

    Khodidas

  • Hi,

      I don't know why it would take several minutes to connect if you have a direct connection to the PC. Are you using a cross-over cable? Can you try on a real network with a switch? Do you still have the same connection time problem? 

  • Hi Charles,

    My concern is that not taking time for connection. as MCu is client and PC is server, But my server app is not working but as mcu is connected with ethernet 

    cable, it will try to connect but, due to stopped or non running server app, connect function returns with error -1, so in this scenario, connect function takes time to return error. so  i want to reduce that time.

    Regards

    Khodidas

  • Hi,

    as MCu is client and PC is server, But my server app is not working but as mcu is connected with ethernet 

    cable, it will try to connect but, due to stopped or non running server app, connect function returns with error -1,

      I'm not sure I'm following you as you have a long sentence. It seems to me that your server app is taking a long time to accept the connection request from the client. If this is the server application running on your PC that is causing the issue then I cannot help you as I have limited knowledge on the PC side applications. I would suggest you try out some freeware server utility for basic testing and compare against your own. https://www.hw-group.com/software/hercules-setup-utility