2401.net
工作总结范文网
全站搜索:
您现在的位置:首页 > 幼儿教育 > 幼儿读物幼儿读物

代码

发布时间:2014-06-22 23:29:12  

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
void main()
{
system("color 0d");
struct swphdr //发送
{
unsigned long seqnum;
unsigned long acknum;
unsigned short flags;
};
struct sendq_slot
{
unsigned short timeout; //超时
unsigned long msg;
struct sendq_slot *next;
};
struct recvq_slot //接收
{
unsigned short received;
unsigned long msg;
struct recvq_slot *next;
};
struct swpstate //缓存
{
unsigned long lar;
unsigned long lfs;
unsigned long sws;
struct swphdr hdr;
unsigned long rws;
struct sendq_slot *sendq;
unsigned long nfe;
struct recvq_slot *head;
}swpstate1;
unsigned long a;
int flag,b;

//发送
struct sendq_slot *sendq_rear,*sendp,*p3,*p4; //设定变量
struct recvq_slot *recvp,*recvq_rear,*p1,*p2;
swpstate1.head=NULL; //变量初始值为空
swpstate1.sendq=sendq_rear=(struct sendq_slot*)malloc(sizeof(struct sendq_slot));
if(!swpstate1.sendq) exit(1);
sendq_rear->next=NULL;
printf("**************请输入窗口大小:*****************\t");
scanf("%ld",&swpstate1.sws); //输入窗口大小
swpstate1.rws=swpstate1.sws; //把窗口的值赋给变量
if (swpstate1.sws>0)
{
printf("**********请输入第一个帧的序列号:**************\t");
scanf("%ld",&swpstate1.hdr.seqnum); //输入第一帧序列号
}
swpstate1.nfe=swpstate1.hdr.seqnum; //把第一帧的值放进缓冲区内
sendp=(struct sendq_slot*)malloc(sizeof(struct sendq_slot));
if(!sendp) exit(1);
sendp->msg=swpstate1.hdr.seqnum;
sendp->timeout=1;
sendp->next=NULL;
sendq_rear->next=sendp;
sendq_rear=sendp;
--swpstate1.sws;
swpstate1.lfs=swpstate1.hdr.seqnum; //最近发送的帧取值
swpstate1.lar=swpstate1.hdr.seqnum; //最近收到的确认帧取值
do
{
while(swpstate1.sws>0) //当窗口大小大于0时,执行以下循环
{
sendp=(struct sendq_slot*)malloc(sizeof(struct sendq_slot));
if(!sendp) exit(1);
sendp->msg=swpstate1.lfs+1; //如果输入的帧序号大于之前帧序号,那么窗口向前滑动
sendp->timeout=1;
sendp->next=NULL;
sendq_rear->next=sendp;
sendq_rear=sendp;
--swpstate1.sws;
++swpstate1.lfs;
}
swpstate1.hdr.acknum=0; //ACK清空
swpstate1.hdr.flags=0; //存储缓冲区清空
printf("**********目前发送的报文段序号:**************\t%ld\n",swpstate1.lar); //输出最近收到的ACK的帧序号
printf("**********目前需要发送的帧序号:***************\t%ld\n",swpstate1.lfs); //输出最近发送帧序号

//接收
if(swpstate1.hdr.flags==0) //上次输入的数据帧被放在缓存区,输入区被清空
{
do //如果继续接收数据帧则实行下面循环
{
prin

网站首页网站地图 站长统计
All rights reserved Powered by 工作总结范文网
copyright ©right 2010-2011。
文档资料库内容来自网络,如有侵犯请联系客服。zhit325@qq.com