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.

RTOS/TM4C1292NCPDT: Multiple TCP connection opening support in Ti NDK

Part Number: TM4C1292NCPDT

Tool/software: TI-RTOS

Hi,

i have modified tcpEcho project for listening TCP 502 port for any incoming packet and process the incoming packets in my DUT.

here i have two different PC application will be sending the packets to 502 ports. the problem is i will not be able to establish the connection of one application when another application is already connected. is the intended behavior of NDK stack or it can be modified through NDK settings. if so where is the typical configuration need to be done to support multiple tcp channel connection?

Regards

Bala

  • Hi Bala,

    This should be possible. How are you setting up the listening socket?

    Todd
  • Hello Todd,

    I have used Global.networkOpenHook = "&netOpenHook";

    inside netOpenHook function i am creating one dynamic task as follows.

    void netOpenHook()

    {

       Task_Handle taskHandle;

       Task_Params taskParams;

       Task_Handle tftpTaskHandle;

       Task_Params tftpTaskParams;

       Error_Block eb;

       /* Make sure Error_Block is initialized */

       Error_init(&eb);

       /*

        *  Create the Task that farms out incoming TCP connections.

        *  arg0 will be the port that this task listens to.

        */

       Task_Params_init(&taskParams);

       taskParams.stackSize = MODBUSHANDLERSTACK;

       taskParams.priority = 1;

       taskParams.arg0 = MODBUSPORT;

       taskHandle = Task_create((Task_FuncPtr)ModbusHandler, &taskParams, &eb);

       if (taskHandle == NULL) {

           System_printf("netOpenHook: Failed to create modbusHandler Task\n");

       }

       System_flush();

    }

    my dyanamic task will initilize Modbus tcp stack and keep listen for any incoming packets on 502 port.

    int ModbusHandler(UArg arg0, UArg arg1)
    {
    /*

    * Initialize the Modbus source code library.
    */

    /* Initialize the timers */

    /* Initialize application context */

    /* Initialize the Target configuration Structure */

    /* Initialize the Channel Structure */

    /* Initialize IO Config Structure*/

    // use TCP since it makes sample easier to use on a PC
    IOCnfg.type = IOC_TYPE_TCP;

    /* name displayed in analyzer window */
    strcpy(IOCnfg.iocTCP.chnlName, "IOC MB Slave");

    /* *.*.*.* allows any client to connect*/
    strcpy(IOCnfg.iocTCP.ipAddress, "*.*.*.*");

    /* The default ipPort for Modbus is 502.
    */
    IOCnfg.iocTCP.ipPort = 502;
    IOCnfg.iocTCP.mode = IOCTCP_MODE_SERVER;
    linkConfig.type = MBLINK_TYPE_TCP;

    pSclChannel = mbchnl_openChannel(pApplContext, NULL, NULL, &linkConfig, &physConfig, &IOCnfg, &targConfig);
    if(pSclChannel == NULL)
    {
        /* Failed to open */
      SYSPRINT("Failed to open channel, exiting program \n");

      /* Sleep for 10 seconds before exiting */

      Task_sleep(1000);
       return (1);
    }

    /* Initialize and open Modbus slave session */
    smbsesn_initConfig(&sesnConfig);
    pSclSession = (SESN *)smbsesn_openSession(pSclChannel, &sesnConfig, NULL);

    if(pSclSession == NULL)
    {
         /* Failed to open */
        TSYSPRINT("Failed to open session, exiting program \n");

       /* Sleep for 10 seconds before exiting */

       Task_sleep(1000);
        return (1);
    }

    while(1)
    {
       checkTimer();
       checkForInput(pApplContext);
      Task_sleep(10);
    }
    }

     

    inside open channel, tcp_socket thread will be created.


    My NDK Configuration as follows.

    /* ================ NDK configuration ================ */
    var Ndk = xdc.loadPackage('ti.ndk.config');
    var Global = xdc.useModule('ti.ndk.config.Global');
    var Ip = xdc.useModule('ti.ndk.config.Ip');
    var Udp = xdc.useModule('ti.ndk.config.Udp');
    var Tcp = xdc.useModule('ti.ndk.config.Tcp');

    Global.IPv6 = false;
    Global.stackLibType = Global.MIN;
    Global.networkOpenHook = "&netOpenHook";

    /* automatically call fdOpen/CloseSession for our sockets Task */
    Global.autoOpenCloseFD = true;


    Global.pktNumFrameBufs = 10;
    Global.memRawPageCount = 6;
    Global.ndkThreadStackSize = 4096;
    Global.lowTaskStackSize = 1024;
    Global.normTaskStackSize = 1024;
    Global.highTaskStackSize = 1024;
    Tcp.transmitBufSize = 4096;
    Tcp.receiveBufSize = 4096;

    i am also encountering another issue - when my client tcp application is trying to connect and disconnect with my DUT for almost 10 times, then i am getting the console message as follows and there after power cycle is required to establish the tcp connection again. but ping is working even though tcp is not working.

    during this condition i have checked the stack and heap size in ROV, where it is having enough memory in all the task.

    Can you please help me to close ASAP? its very critical issue in my project.

    versions of software is used as follows

    tirtos_tivac_2_16_01_14

    bios_6_45_02_31

    ndk_2_25_00_09

    tidrivers_tivac_2_16_01_13

     

    Regards

    Bala

  • Bala,

    Where is the listen call? For example in the TCPEcho example in TI-RTOS, there is the following
    status = listen(server, NUMTCPWORKERS);

    The NUMTCPWORKERS (3) limits the number of backlog of connections.

    Can you confirm that you can run TCPEcho on the target and TCPSendReceive on different PCs?

    Todd
  • Hi Todd,

    This is the listen call i am using "listen(listenSocket, IOCTCP_BACKLOG)" where IOCTCP_BACKLOG = 5.

    >>>Can you confirm that you can run TCPEcho on the target and TCPSendReceive on different PCs?
    - Let me try on this.

    >>>i am also encountering another issue - when my client tcp application is trying to connect and disconnect with my DUT for almost 10 times, then i am getting the console message as follows and there after power cycle is required to establish the tcp connection again. but ping is working even though tcp is not working.

    --- Do you have any suggestion for this problem. because this is an serious issue when compared to multiple connection?

    Regards
    Bala
  • Hello Guys,

    Finally i found the issue for Modbus TCP disconnect after 10th time. for TCP socket close we have used shutdown() API instead of Close() API.

    Reagrds
    Bala