UDP reliable data service implementation

夙愿已清 提交于 2019-12-12 02:47:39

问题


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


回答1:


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

It has a standard.




回答2:


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!


来源:https://stackoverflow.com/questions/8353970/udp-reliable-data-service-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!