UDP可靠数据服务实现

发布于 2024-12-19 04:36:54 字数 81 浏览 2 评论 0原文

我正在尝试使用 UDP 实现简单的数据传输。我的校验和有问题,给定一个包含数据的数据包,我应该如何实现校验和?还知道如何实现超时以便触发重传吗?谢谢

I'm trying to implement a simple data transfer using UDP. I have a problem for the checksum, given a packet containing the data, how should I implement the checksum? also any idea how to implement the timeouts so it will trigger the retransmission ? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-12-26 04:36:55

为什么不尝试 Reliable UDP,请参阅 http://en.wikipedia.org/wiki/Reliable_User_Datagram_Protocol

有一个标准。

Why not try Reliable UDP, see http://en.wikipedia.org/wiki/Reliable_User_Datagram_Protocol

It has a standard.

掩于岁月 2024-12-26 04:36:55
here's one approach for the internet checksum

unsigned short checkSum() {
    unsigned long sum = 0;
    int i;
    for(i=0; i < your packet length ; i++) {
        sum += (your packet data[i] & 0xFFFF);
    }
    while (sum >> 16) {
        sum = (sum & 0xFFFF) + (sum >> 16);
    }
    sum = ~sum;     
    return ((unsigned short) sum);
}

for the retransmission, you can set alarm to trigger timeout 
when packet is loss. you can do something using
signal (SIGALRM, timeout function);

Hope it helps!
here's one approach for the internet checksum

unsigned short checkSum() {
    unsigned long sum = 0;
    int i;
    for(i=0; i < your packet length ; i++) {
        sum += (your packet data[i] & 0xFFFF);
    }
    while (sum >> 16) {
        sum = (sum & 0xFFFF) + (sum >> 16);
    }
    sum = ~sum;     
    return ((unsigned short) sum);
}

for the retransmission, you can set alarm to trigger timeout 
when packet is loss. you can do something using
signal (SIGALRM, timeout function);

Hope it helps!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文