欢迎来到天天文库
浏览记录
ID:16128991
大小:17.50 KB
页数:3页
时间:2018-08-08
《停等协议程序设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#includeclient(){inti=0;charch,a[20],c;FILE*fp1,*fp2;textcolor(3);clrscr();printf("Receive:");fp1=fopen("c:\server1.txt","rb");ch=fgetc(fp1);fp2=fopen("c:um1.txt","rb");while(ch!=''&&ch!=EOF){c=fgetc(fp2);if(c=='0'){printf("sendagain
2、n");}elseif(c=='1'){printf("%c",ch);printf("tsuccess");ch=fgetc(fp1);}sleep(2);}fclose(fp1);fclose(fp2);}main(){client();printf("Pleaseanykey.....");getchar();}#include#includeserver(){inti,t;charch,a[20],c;FILE*fp1,*fp2,*fp3,*fp4;textcolor(2);clr
3、scr();i=0;t=0;printf("Sentamessage:");fp1=fopen("c:\server.txt","wb");/*存要发送的数据*/fp3=fopen("c:\server1.txt","wb");ch=getchar();fputc(ch,fp1);fputc(ch,fp3);while(ch!=''){ch=getchar();fputc(ch,fp1);fputc(ch,fp3);}fclose(fp1);fclose(fp3);fp2=fopen("c:um.txt","wb"
4、);fp4=fopen("c:um1.txt","wb");for(i=0;i<30;i++){t=rand()%2;if(t==0){c='0';fputc(c,fp2);fputc(c,fp4);}elseif(t==1){c='1';fputc(c,fp2);fputc(c,fp4);}}fclose(fp2);fclose(fp4);fp1=fopen("c:\server.txt","rb");/*开始发送信息*/ch=fgetc(fp1);fp2=fopen("c:um.txt","rb");c=fgetc
5、(fp2);while(ch!=''){printf("%c",ch);a[i]=ch;if(c=='1'){printf("ttACK");i++;ch=fgetc(fp1);}else{ch=a[i];}c=fgetc(fp2);printf("");sleep(2);}fclose(fp1);fclose(fp2);}main(){server();printf("Pleaseanykey.....");getchar();}
此文档下载收益归作者所有