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.

the accept() in ndk run falsely

Hi, in one 6678 board, I use accept() in ndk to accept new connection from another board, my program is like the following:

NetworkOpen()

{

         TaskCreate(taskFxn, "name", arg0,...);

}

void taskFxn()

{

     SOCKET s;

     struct sockaddr_in servaddr, cliaddr;

     s = socket(AF_INET, TCP_STREAM, 0);

     bind(s, (PSA)&servaddr, sizeof(servaddr);

     listen(s, MAXCONNECT);

     SOCKET cli_sock;

     while(1)

    {

           if((cli_sock = accept(s, (PSA)&cliaddr, &len_cliaddr)) == INVALID_SOCKET)

           {

                 printf("%d\n", fdError());                     ------- (1)

            }

            else

            {

                 printf("accpeted a new connection.";           -------------(2)

             }

}

When I debug the code above, after step over the accept(), the program is in running status, it doesn't execute the following (1) or (2) in the program. what is the matter? can anyone help me?

  • Is your protocol IPPROTO_TCP when creating the socket? what is the value for cli_sock?

    From the source code:

    int SockNew( int Family, int Type, int Protocol,
                 int RxBufSize, int TxBufSize, HANDLE *phSock )

    And the type only have the following:

    /* Socket Types */
    #define SOCK_STREAM     1               /* stream socket */
    #define SOCK_DGRAM      2               /* datagram socket */
    #define SOCK_RAW        3               /* raw-protocol interface */
    #define SOCK_STREAMNC   4               /* non-copy stream socket */
    #ifdef _INCLUDE_NIMU_CODE
    #define SOCK_RAWETH     5               /* non-copy raw eth socket */
    #endif

    Is TCP_STREAM in your code defined as one of the above types?

    Regards, Eric

  • Hi, sorry, TCP_STREAM is a writing careless. it is SOCK_STREAM.

  • it is solved, the reason is that accept() is blocking.