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.

c6678 ndk TCP connect

s = socket(AF_INET, SOCK_STREAMNC, IPPROTO_TCP);  

if( s == INVALID_SOCKET )  

{   

printf("failed socket create (%d)\n",fdError());   goto leave;

 }

 // Prepare address for connect  

bzero( &sin1, sizeof(struct sockaddr_in) );  

sin1.sin_family      = AF_INET;  

sin1.sin_len         = sizeof( sin1 );  

sin1.sin_addr.s_addr = IPAddr;  

sin1.sin_port        = htons(1001);

 // Configure our timeout to be 5 seconds  

timeout.tv_sec  = 5;  timeout.tv_usec = 0;

setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) );  

setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );

 // Connect socket  

if ( connect( s, (PSA) &sin1, sizeof(sin1) ) < 0 )

 {  

 printf("failed connect (%d)\n",fdError());   

goto leave;  }

 

您好!

新建一个tcp socket connect( s, (PSA) &sin1, sizeof(sin1) )不上,显示错误信息

== Start TCP Send Test ==

00006.000 TCP: Retransmit Timeout

00030.000 TCP: Retransmit Timeout

00075.000 TCP: Keep Timeout

failed connect (60)

== End TCP Send Test ==

我在论坛里面没有找到相关的解释

谢谢!

  • fdOpenSession((HANDLE)TaskSelf() );

    SOCKET s;
    struct sockaddr_in sin1,sin2;
    UINT32 test,j;
    char *pBuf = 0;
    struct timeval timeout;
    UINT32 startS, startMS;
    UINT32 endS, endMS;


    printf("\n== Start TCP Send Test ==\n");

    // Create test socket
    s = socket(AF_INET, SOCK_STREAMNC, IPPROTO_TCP);
    if( s == INVALID_SOCKET )
    {
    printf("failed socket create (%d)\n",fdError());
    goto leave;
    }

    // Prepare address for connect
    bzero( &sin1, sizeof(struct sockaddr_in) );
    sin1.sin_family = AF_INET;
    sin1.sin_len = sizeof( sin1 );
    sin1.sin_addr.s_addr = inet_addr(LocalIPAddr);
    sin1.sin_port = htons(1000);

    // Connect socket
    if ( bind( s, (PSA) &sin1, sizeof(sin1) ) < 0 )
    {
    printf("failed bind (%d)\n",fdError());
    goto leave;
    }
    // Configure our timeout to be 5 seconds
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) );
    setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );


    // Prepare address for connect
    bzero( &sin2, sizeof(struct sockaddr_in) );
    sin2.sin_family = AF_INET;
    sin2.sin_len = sizeof( sin2 );
    sin2.sin_addr.s_addr = inet_addr(dstIPAddr);
    sin2.sin_port = htons(1000);
    // Connect socket
    if ( connect( s, (PSA) &sin2, sizeof(sin2) ) < 0 )
    {
    printf("failed connect (%d)\n",fdError());
    goto leave;
    }

    改写过后出现failed connect(61)

  • 是不是服务器端没有开?

  •       mcsdk的client例程,用DaemonNew创建端口1000的dtask_tcp_datasrv进程,用recv.exe测试没有问题,但是自己用Task_create创建任务,然后创建socket连接不上,端口也使用的是1000

          没有明白您说的服务器端没有开?


  • 您好,请问您的问题解决没有,我也遇到跟您一样的问题。