Microchip
直播中

赵媛

7年用户 153经验值
私信 关注
[问答]

TCPIP_UDP_Bind()阻止udp客户端发送UDP数据包

在上面的代码中,如果我删除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_MULti_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!

回帖(6)

云达贞

2019-3-13 07:24:29
您所调用的绑定操作清除套接字的接口选择。当接口=0时,套接字将无法传输。使用ATCPIPUDUpSoCKETNETSET()来选择绑定后的正确接口,或者在绑定调用中提供适当的IPv6地址。另一方面,您真的需要特定的本地端口吗?也许你可以完全避免Band()。

以上来自于百度翻译


      以下为原文

    The bind operation that you call clears the interface selection for the socket. With an interface == 0, the socket won't be able to transmit. Use a TCPIP_UDP_SocketNetSet() to select the proper interface after your bind.
Or provide a proper IPv6 address of the interface in the bind call.
 
P.S. On the other hand, do you really need a specific local port? Maybe you can avoid the Bind() completely.
举报

陈芳

2019-3-13 07:36:38
你好,rainad,谢谢你的澄清。我可以在调用绑定中指定IPv6地址后得到它的工作。我确实需要一个特定的端口来为我的应用程序做广告,因为我在网络中的其他设备上发布我唯一的端口号,并且我的服务的所有事务都将在这个唯一的端口上运行。

以上来自于百度翻译


      以下为原文

    Hi rainad,
Thank you for the clarification. I could get it working after specifying the IPv6 address in the call to bind. 
I do need a specific port for my application as I advertise my unique port number to the other devices in the network and all the transactions of my service would operate on this unique port.
举报

陈芳

2019-3-13 07:46:21
你能帮我解决另一个问题吗?HTTP://www. McCHIP.COM/FUMUSS/M9566ASPXIT一直阻止我用我的PoC进一步发展。

以上来自于百度翻译


      以下为原文

    Could you also help me with my other question?
http://www.microchip.com/forums/m995566.aspx
 
This has been blocking me from progressing further with my POC.
 
举报

云达贞

2019-3-13 07:55:51
我想你可以在打开插座后为你的本地端口做广告,这样就消除了绑定的要求。请看另一个帖子,我做了一些评论。

以上来自于百度翻译


      以下为原文

    I guess you can advertise your local port after you open the socket - and thus eliminate the call for Bind.
Please see the other post, I made some comments.
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分