tcp / udp client problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

tcp / udp client problem

491 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ccrbs on Thu Jul 25 06:35:46 MST 2013
Using tcpecho and udpecho to make tcp/udp serve, the sample can work together with freertos and lwip. I start to make tcp client. I add the following thread for it, but it can not setup a connection with PC(tcp serve). I found that I get the err=-10 after run function:netconn_connect. who can help to answer it or give the client sample code?

Mani thanks!


void tcp_client_thread(void *arg) 

    struct netconn *conn; 
    struct netbuf        *TCPNetbuf; 

    err_t myerr; 
    char Text[]="hello i am client!"; 
    static struct ip_addr serverip;            
    static unsigned short serverport;       
 
 
    serverip.addr = htonl(0xC0A9015A);       //192.161.1.90 
    serverport=60000;     
    conn = netconn_new(NETCONN_TCP);     
    netconn_bind(conn,NULL,60000);             
 
/* About a 1/7s delay */
vTaskDelay(configTICK_RATE_HZ / 14);
    printf("\033[2JTCP connect....\n");  
    myerr=netconn_connect(conn,&serverip,serverport);           
    if(myerr==ERR_OK) 
    { 
        printf("\033[2JTCP connect ok\n"); 
    }else{ 
        printf("\033[2JTCP connect err=%d\n",myerr); 
    } 

    TCPNetbuf =netbuf_new(); 
//  netbuf_alloc(TCPNetbuf, 40); 

    netbuf_ref(TCPNetbuf,Text,sizeof(Text)); 
  
    while(1) 
    {        
/* About a 1s delay */
vTaskDelay(configTICK_RATE_HZ);
            netconn_send(conn,TCPNetbuf); 
            netconn_write(conn,(void *)&Text,sizeof(Text),NETCONN_NOCOPY); 
vTaskDelay(configTICK_RATE_HZ / 14);
    } 
Labels (1)
0 Kudos
0 Replies