在上面的代码中,如果我删除TCPIpU-UppIbDUE(),代码会按预期的方式运行,并将数据发送到远程端口。但是,当我在本地绑定时,远程主机最初不接收任何数据。然而,当远程设备在端口LoalAlxPoT上向上述客户端发送数据时,客户端将数据发送到远程设备。为什么客户端设备在使用本地绑定时需要一个初始触发器?我在这里做错了什么?任何帮助将不胜感激!
以上来自于百度翻译
以下为原文
case APP_TCPIP_OPENING_CLIENT:
{
SYS_CMD_READY_TO_READ();
if (APP_Send_Packet)
{
APP_Send_Packet = false;
IPV6_ADDR addr;
TCPIP_Helper_StringToIPv6Address(APP_Hostname_Buffer, &addr);
uint16_t port = atoi(APP_Port_Buffer);
appData.clientSocket = TCPIP_UDP_ClientOpen(IP_ADDRESS_TYPE_IPV6,
port,
(IP_MUL
ti_ADDRESS*) &addr);
if (appData.clientSocket == INVALID_SOCKET)
{
SYS_CONSOLE_MESSAGE("Could not start connectionrn");
appData.clientState = APP_TCPIP_OPENING_CLIENT;
}
SYS_CONSOLE_MESSAGE("Starting connectionrn");
uint16_t local_port = 50728;
if(!TCPIP_UDP_Bind(appData.clientSocket, IP_ADDRESS_TYPE_IPV6, local_port,0))
{
SYS_CONSOLE_PRINT("Could not bind to local port %drn",local_port);
}
appData.clientState = APP_TCPIP_WAIT_FOR_CONNECTION;
}
}
case APP_TCPIP_WAIT_FOR_CONNECTION:
{
if (!TCPIP_UDP_IsConnected(appData.clientSocket))
{
break;
}
if(TCPIP_UDP_PutIsReady(appData.clientSocket) == 0)
{
break;
}
TCPIP_UDP_ArrayPut(appData.clientSocket, (uint8_t*)APP_Message_Buffer, strlen(APP_Message_Buffer));
TCPIP_UDP_Flush(appData.clientSocket);
appData.clientState = APP_TCPIP_WAIT_FOR_RESPONSE;
appData.mTimeOut = SYS_TMR_SystemCountGet() + 15*SYS_TMR_SystemCountFrequencyGet();
}
break;
In the above code, if I remove TCPIP_UDP_Bind(), the code functions as expected and sends out the data to the remote port. But, when I have the local bind in place, the remote host doesn't receive any data initially. However, when the remote device sends data to the above client on port local_port, then the client sends data to the remote device. Why does the client device require an initial trigger when I use local binding? What am I doing wrong here? Any help would be appreciated!