EVT307\EXAM\ETH中 DNS和TCPClient的交接有问题啊。。。


我把EVT307\EXAM\ETH中 DNS 获得的IP填到 TCPCLinet里面,建立不了链接啊。。。。

DNS Test
SystemClk:120000000
net version:14
mac addr:38 3b 26 89 50 91
WCHNET_LibInit Success
PHY Link Success
DHCP Success
IPAddr = 192.168.10.101
GWIPAddr = 192.168.10.1
IPAddr = 255.255.255.0
DNS1: 192.168.10.1
DNS2: 0.0.0.0
Host Name = www.wch.cn
IP= 58.213.45.186
Connecting to: 58.213.45.186
WCHNET_SocketCreat 0
Error: 1D

Error: 17

void WCHNET_DNSCallBack(const char *name, u8 *ipaddr, void *callback_arg)
{
    u8 i;
    if(ipaddr == NULL)
    {
        printf("DNS Fail\r\n");
        return;
    }
    printf("Host Name = %s\r\n", name);
    printf("IP= %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
    memcpy(DESIP, ipaddr, 4);
    if(callback_arg != NULL)
    {
        printf("callback_arg = %02x\r\n", (*(u8 *)callback_arg));
    }
    WCHNET_DNSStop();                                                          //stop DNS,and release socket
    WCHNET_CreateTcpSocket();
    i = WCHNET_SocketConnect(SocketId);                        //make a TCP connection
    mStopIfError(i);
                                                       //Create a TCP connection

}


void WCHNET_CreateTcpSocket(void)
{
    u8 i;
    SOCK_INF TmpSocketInf;

    memset((void *) &TmpSocketInf, 0, sizeof(SOCK_INF));
    printf("Connecting to: %d.%d.%d.%d \r\n", (u16)DESIP[0], (u16)DESIP[1],
           (u16)DESIP[2], (u16)DESIP[3]);

    memcpy((void *) TmpSocketInf.IPAddr, DESIP, 4);
    TmpSocketInf.DesPort = desport;
    TmpSocketInf.SourPort = srcport++;
    TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
    TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
    i = WCHNET_SocketCreat(&SocketId, &TmpSocketInf);
    printf("WCHNET_SocketCreat %d\r\n", SocketId);
    mStopIfError(i);



}


您好,根据报错信息很可能是未配置TCP连接个数,这个参数要在net_config.h中配置,如下图所示的地方。另外通过这种方式与该服务器连接也不一定成功,因为不知道该服务器的TCP listening端口。1.png


感谢!

药到病除!

就说WCH的技术支持名不虚传!


DNS Test
SystemClk:120000000
net version:14
mac addr:38 3b 26 89 50 91
WCHNET_LibInit Success
WCHNET_CreateTcpSocket finish
PHY Link Success
DHCP Success
IPAddr = 192.168.10.101
GWIPAddr = 192.168.10.1
IPAddr = 255.255.255.0
DNS1: 192.168.10.1
DNS2: 0.0.0.0
Host Name = www.wch.cn
IP= 58.213.45.186
Connecting to: 58.213.45.186
WCHNET_SocketCreat 0
TCP Connect Success


只有登录才能回复,可以选择微信账号登录