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.

TCP/IP server and client programming issue

Hi,

We are using Concerto f28m35 controller in our project.  we are facing a problem in TCP/IP protocol program,

1. we are creating 20 clients at the pc side with different port and IP address and controller board as a server.

2. All 20 clients will connect to the server, server have 20 different ports for it. 

3. here clients are taking more time to connect with the server.

we need your suggestion to solve this.

But we tried with vice-verse PC as sever and 20 control boards as server, it working fine it will connect immediately.

Please help to solve above problem.

thank you

Basavanagouda.

  • Which version of TIRTOS are you using?

    Steve
  • HI steve,

    Currently we are using tirtos_c2000_2_00_01_23 version.


    Thank you
    Basavanagouda.
  • Hi Basavanagouda,

    Could you please clarify on the problem you are seeing?

    Do all 20 attempts to connect (from PC to Concerto board) succeed?  Or are there errors?

    What happens when one of these connections succeeds?  Does it stay connected?  Or does the PC quickly make some requests to the Concerto server, and close the connection, for example?

    Basvanagouda G said:
    . here clients are taking more time to connect with the server.

    Can you clarify on this? More time?  Do they all succeed in connecting, but it just "takes long?"

    Steve

  • Hi,

    Yes all 20 boards(clients ) are able to connect to the pc application. They will stay with the connection and there is no error.
    When client is connected to server we are not closing the connection.

    few clients will connect immediately but few will take more than 60 sec.
    How we can reduce this time?


    Thank you.
    Bsavanagouda
  • Are all 2o clients originating from the same PC? If they are from different PCs, is it always the same PCs which take a long time to connect?
    If all the clients originate from the same PC, are you certain they're initiating their TCP connections at the same time? If the connection requests always start in a certain order, is it always the later clients that are delayed? Is there a pattern to it?

    Alan
  • hi,

    Yes, all 20 clients are originating from the same pc and they are initiating their TCP connections at the same time. there is no particular pattern for connection, all boards will try to connect at a time.

    regards
    Basavanagouda
  • Hi Basavanagouda,

    I'm wondering if you can please clarify more on what Alan asked prior.  In particular, it would help us to know which clients connect, which fail, how many connect and fail, if they are the same clients each time, and if the number of successful connects/fails is always the same/consistent.  And also, I'm wondering in particular about the scenario where the PC is the client (the 20 clients) and the Concerto board is the server (not vice versa).

    If you have 20 clients connecting at once, can you add some code or prints to your PC app, that would let you know which clients successfully connect, and which ones don't?  This would help us to see if say, the first 10 clients always connect successfully, for example, and if they are always the same 10 or different between test runs.

    Also, can you share your server side code (Concerto/NDK code)?  I'm wondering you could add some checks for failure on your accept() Call, and then print out some meaningful messages based on that (e.g. if there is a timeout, or if accept() fails due to lack of memory, etc.).

    Another question, what is the size of your TCP socket buffers?  You could check this by looking at your *.cfg file, under the NDK buffer size settings.  Note that if you have any call to setsockopt() that changes the size of any socket buffers, you would need to let us know that, too.  I'm wondering if you are running out of memory.  Each socket created will result in an allocation of [TCP RX buffer size + TCP TX buffer size], which can add up quickly if you've configured large TX/RX buffer sizes for the socket.

    Lastly, it may help you to print out a dump of the TCP socket table.  I would suggest to try doing this with each return from accept() in your code.

    You can use the following utility function for this.  You might want to change printf() to System_printf().  Also, you should put this into its own, separate C file, then just make an extern declaration for DumpSockets() in the file you want to call it from:

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    #include <ti/ndk/inc/netmain.h>
    #include <_stack.h>
    

    /* used by DumpSockets() */
    static char *States[] = { "CLOSED","LISTEN","SYNSENT","SYNRCVD",
                              "ESTABLISHED","CLOSEWAIT","FINWAIT1","CLOSING",
                              "LASTACK","FINWAIT2","TIMEWAIT" };

    /* * copied from ti/ndk/tools/console/consock.c */ void DumpSockets(uint SockProt) { UINT8 *pBuf; int Entries,i; SOCKPCB *ppcb; char str[40]; pBuf = mmBulkAlloc(2048); if( !pBuf ) return; /* Use llEnter / llExit since we're calling into the stack */ llEnter(); Entries = SockGetPcb( SockProt, 2048, pBuf ); llExit(); printf("\nLocal IP LPort Foreign IP FPort State\n"); printf("--------------- ----- --------------- ----- -----------\n"); for(i=0; i<Entries; i++) { ppcb = (SOCKPCB *)(pBuf+(i*sizeof(SOCKPCB))); NtIPN2Str( ppcb->IPAddrLocal, str ); printf("%-15s %-5u ", str, htons(ppcb->PortLocal) ); NtIPN2Str( ppcb->IPAddrForeign, str ); printf("%-15s %-5u", str, htons(ppcb->PortForeign) ); if( SockProt == SOCKPROT_TCP ) printf(" %s\n",States[ppcb->State]); else printf("\n"); } printf("\n"); mmBulkFree( pBuf ); }

    (you may or may not need more header file includes, Alan should be able to help with that if you do)

    You can call DumpSockets as follows:

        /* print out sockets info */
        DumpSockets(SOCKPROT_TCP);
    

    Hope this helps,

    Steve