首页 开发技术 C     /    GoBackN协议的C言语实现

GoBackN协议的C言语实现

上传者: gubinno | 上传时间:2019/7/26 21:18:43 | 文件大小:425KB | 文件类型:rar
GoBackN协议的C言语实现
模仿数据链路层的gobackn协议/*该协议是搭载ack的回退n步协议*/#include#include"protocol.h"#definemax_seq7#defineflag126#defineESC100#definewait_time2700 //发送计时器等待的时间#defineack_wait_time280staticintphl_ready=0;unsignedcharbuf[max_seq+1][270];unsignedcharack[8];//发送空的ack帧unsignedcharin_buf[600],last_buf[520];//接收时的缓冲区;去掉冗余之后的缓冲区,为防备因误码两帧合并为一帧而定义了很大一个数组intnbuffered=0;//发送的帧数intbuf_size[max_seq+1];//记下以发送各帧的帧长intnext_frame_to_send=0;intframe_in_phl=0;//用于成帧intframe_expected=0;intack_expected=0;intbetween(inta,intb,intc){ if(((a<=b)&&(b<c))||((c<a)&&(a<=b))||((b<c)&&(c<a))) return1; elsereturn0;}//判断帧尾,防止出现误判escescflag为数据的情况intend_flag(intin_len){ intcount=0; inti; if(in_len=0;i--)//记录flag前的esc数目 count++; returncount%2;//若flag前的esc为偶数,则为帧尾}//成帧函数--数据帧voidsend_frame(char*my_buf,intlen){ intn; buf[frame_in_phl][0]=(frame_expected+max_seq)%(max_seq+1); //ack buf[frame_in_phl][1]=frame_in_phl; //发送帧的帧号 for(n=0;n<len;n++) buf[frame_in_phl][n+2]=my_buf[n]; //将处理过的新帧赋值到缓冲区中 len=len+2; *(unsignedint*)(buf[frame_in_phl]+len)=crc32(buf[frame_in_phl],len); //在原始帧的基础上加检验和 buf_size[frame_in_phl]=len+4; //记录当前帧的长度,包括3个帧头,4个检验和 nbuffered=nbuffered+1; //缓冲区占用数加一 frame_in_phl=(frame_in_phl+1)%(max_seq+1);}//成帧函数--ack帧voidsend_ack() //ack帧的处理{ ack[0]=(frame_expected+max_seq)%(max_seq+1); ack[1]=max_seq+10; //ack帧的序号位,使ack[1]==frame_expected恒不成立 *(unsignedint*)(ack+2)=crc32(ack,2); //在原始帧的基础上加检验和}//主函数intmain(intargc,char**argv){intevent,arg,n,m,i,j,len=0,in_len=0; unsignedcharmy_buf[260]; intphl_wait=0;//在物理层中还没有被发送的帧protocol_init(argc,argv);enable_network_layer();for(;;){event=wait_for_event(&arg);switch(event){caseNETWORK_LAYER_READY: 本软件ID:1200736

文件下载

资源详情

[{"title":"(36个子文件425KB)GoBackN协议的C语言实现","children":[{"title":"gobackn","children":[{"title":"性能测试记录表.doc <span style='color:#111;'>78.00KB</span>","children":null,"spread":false},{"title":"测试数据","children":[{"title":"datalink-Afle.log <span style='color:#111;'>42.49KB</span>","children":null,"spread":false},{"title":"datalink-Bf.log <span style='color:#111;'>63.97KB</span>","children":null,"spread":false},{"title":"datalink-Bfle.log <span style='color:#111;'>42.43KB</span>","children":null,"spread":false},{"title":"datalink-Bf–ber1e-4.log <span style='color:#111;'>64.01KB</span>","children":null,"spread":false},{"title":"datalink-Bfl.log <span style='color:#111;'>68.51KB</span>","children":null,"spread":false},{"title":"datalink-B1e-7.log <span style='color:#111;'>121.92KB</span>","children":null,"spread":false},{"title":"datalink-B5e-5.log <span style='color:#111;'>40.94KB</span>","children":null,"spread":false},{"title":"datalink-B无参数.log <span style='color:#111;'>68.03KB</span>","children":null,"spread":false},{"title":"datalink-Bfs.log <span style='color:#111;'>66.19KB</span>","children":null,"spread":false},{"title":"datalink-Af–ber5e-4.log <span style='color:#111;'>94.09KB</span>","children":null,"spread":false},{"title":"datalink-Af–ber1e-4.log <span style='color:#111;'>63.80KB</span>","children":null,"spread":false},{"title":"datalink-Afl.log <span style='color:#111;'>67.94KB</span>","children":null,"spread":false},{"title":"datalink-A1e-7.log <span style='color:#111;'>121.06KB</span>","children":null,"spread":false},{"title":"datalink-Afs.log <span style='color:#111;'>65.56KB</span>","children":null,"spread":false},{"title":"datalink-Af.log <span style='color:#111;'>63.45KB</span>","children":null,"spread":false},{"title":"datalink-A5e-5.log <span style='color:#111;'>41.01KB</span>","children":null,"spread":false},{"title":"datalink-A无参数.log <span style='color:#111;'>34.84KB</span>","children":null,"spread":false},{"title":"datalink-Bf–ber5e-4.log <span style='color:#111;'>93.09KB</span>","children":null,"spread":false}],"spread":false},{"title":"protocol.h <span style='color:#111;'>1.19KB</span>","children":null,"spread":false},{"title":"datalink.c <span style='color:#111;'>6.61KB</span>","children":null,"spread":false},{"title":"datalink.dsp <span style='color:#111;'>3.49KB</span>","children":null,"spread":false},{"title":"实验报告评语.doc <span style='color:#111;'>37.00KB</span>","children":null,"spread":false},{"title":"datalink.opt <span style='color:#111;'>52.50KB</span>","children":null,"spread":false},{"title":"datalink.ncb <span style='color:#111;'>65.00KB</span>","children":null,"spread":false},{"title":"数据链路层滑动窗口协议的设计与实现-实验报告.doc <span style='color:#111;'>139.50KB</span>","children":null,"spread":false},{"title":"datalink.dsw <span style='color:#111;'>541B</span>","children":null,"spread":false},{"title":"datalink.plg <span style='color:#111;'>252B</span>","children":null,"spread":false},{"title":"Debug","children":[{"title":"protocol.lib <span style='color:#111;'>72.94KB</span>","children":null,"spread":false}],"spread":true},{"title":"Release","children":[{"title":"protocol.lib <span style='color:#111;'>44.55KB</span>","children":null,"spread":false},{"title":"vc60.idb <span style='color:#111;'>33.00KB</span>","children":null,"spread":false},{"title":"datalink.exe <span style='color:#111;'>68.00KB</span>","children":null,"spread":false},{"title":"datalink.obj <span style='color:#111;'>5.12KB</span>","children":null,"spread":false},{"title":"datalink.pch <span style='color:#111;'>176.28KB</span>","children":null,"spread":false}],"spread":true},{"title":"源程序清单-样板.DOC <span style='color:#111;'>49.50KB</span>","children":null,"spread":false},{"title":"流程图.JPG <span style='color:#111;'>77.30KB</span>","children":null,"spread":false}],"spread":false}],"spread":true}]

评论信息

  • xiaoxiaoxiaoQAQ:
    谢谢,参考下2017-12-04
  • qq_24327707:
    不错,非常详细2015-06-18
  • Sam_zZ泽森:
    程序可以运行,但是思路太复杂2015-06-01
  • 最美的时光_:
    程序可以运行,但是思路比较复杂2015-05-29
  • yuweihuangda1234:
    可以运行,需要自己好好研究,呵呵2015-01-05

免责申明

【好快吧下载】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【好快吧下载】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【好快吧下载】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,8686821#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明