簡體   English   中英

單播UDP數據包未命中

[英]Unicast UDP packet miss

單播(一對一)UDP通信,每次收到的數據包都不相同; 如果我在500毫秒的間隔內發送1000個數據包,則會丟失9個數據包。 我正在Windows平台VCC 6.0上工作; 使用sendto系統調用發送以太網數據包。 在主機端,我通過校驗和錯誤或標頭錯誤錯過了數據包。

如果您需要更多詳細信息,請告訴我。 我的議程是我不應該錯過目標端的任何數據包。 任何有關此問題的幫助將不勝感激。

{
    //Initialize local variables 
    MAINAPP(pAppPtr);
    int iResult = 0;
    int sRetVal = 0;
    static char cTransmitBuffer[1024];
    unsigned long ulTxPacketLength =0;
    int in_usTimeOut = 0;
    unsigned short usTimeout = 0;

    S_QJB_POWER_CNTRL S_Out_QJB_Power_Cntrl = {0};

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_ucHeader[0] = QJB_TCP_HEADER_BYTE1;

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_ucHeader[1] = QJB_TCP_HEADER_BYTE2;

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_usCmdID = QJB_ETH_POWER_ON;

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_usCmdResults = 0;

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_usDataSize = sizeof(S_QJB_POWER_CNTRL);

    //Fill the controls & delay
    sRetVal = PowerCntrlStructFill(&pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.U_Tcp_Msg.S_QJB_PowerCntrl,&usTimeout);

    if(sRetVal)
    {
        return sRetVal;
    }

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_usReserved = 0;

    pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.m_usChecksum = 0;
    //Perform Endian Swap
    pAppPtr->objEndianConv.EndianSwap(&pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg.U_Tcp_Msg.S_QJB_PowerCntrl, &S_Out_QJB_Power_Cntrl);

    //Frame the transmission packet 
    QJB_Frame_TXBuffer(cTransmitBuffer, &(pAppPtr->S_Tcp_Handle.Tcp_Tx_Msg), &ulTxPacketLength,(void *)&S_Out_QJB_Power_Cntrl);

    //Send the data to the target
    iResult = sendto(pAppPtr->sktConnectSocket,cTransmitBuffer,ulTxPacketLength,0,(struct sockaddr *)&pAppPtr->g_dest_sin, sizeof(pAppPtr->g_dest_sin));
    if(iResult == SOCKET_ERROR) 
    {
       return QJB_TARGET_DISCONNECTED;
    }

    memset(&pAppPtr->S_Tcp_Handle.Tcp_Rx_Msg,0,sizeof(S_QJB_ETHERNET_PKT));// 1336
    //Send the Command and obtain the response
    sRetVal = QJB_ETHResRev(pAppPtr->sktConnectSocket,&pAppPtr->S_Tcp_Handle.Tcp_Rx_Msg,3);
    return sRetVal;
}

Sathishkumar。

不幸的是,由於UDP無法保證傳送,因此網絡堆棧可以隨時出於任何原因丟棄已發送的數據包。 值得注意的是,數據包也不會到達的訂單的任何訂單保證。

如果訂購和交付對您的應用程序至關重要(我認為確實如此),請考慮切換到TCP。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM