资源简介
实验一.doc 对于滑动窗口协议的介绍
a) 窗口机制
b) 1比特滑动窗口协议
c) 后退n协议
d) 选择重传协议
实验一:实验报告.doc 说明了试验过程和总结等。
SlideWindowSender.exe :发送窗口演示程序
SlideWindowReceiver.exe : 接收窗口演示程序
SlideWindowReceiver:发送窗口源码
SlideWindowSender:接收窗口源码
这只是个模拟程序。
代码片段和文件信息
#include “common.h“
#define RECEIVE_MAX_LENGTH 100
#define SEND_MAX_LENGTH 100
//void (interrupt far *oldhandler)();
void main()
{
Begin:
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1 1 );
err = WSAStartup( wVersionRequested &wsaData );
if ( err != 0 )
{
Sleep(SLEEPMS);
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1
|| HIBYTE( wsaData.wVersion ) != 1 )
{
WSACleanup( );
Sleep(SLEEPMS);
return;
}
SOCKET socksrv = socket(AF_INETSOCK_STREAM0);//监听的套接字
SOCKADDR_IN socketadd;
socketadd.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
socketadd.sin_family = AF_INET;
socketadd.sin_port = htons(7001);
if( SOCKET_ERROR == bind(socksrv(SOCKADDR*)&socketaddsizeof(SOCKADDR)) )
{
printf(“bind err\n“);
WSACleanup( );
Sleep(SLEEPMS);
return;
}
if( SOCKET_ERROR == listen(socksrv5) )
{
printf(“listen err“);
WSACleanup( );
Sleep(SLEEPMS);
return;
}
SOCKADDR_IN sockclient;
int len = sizeof(SOCKADDR);
SOCKET sockconn = accept(socksrv(SOCKADDR*)&sockclient&len);//建立连接的套节字
if(INVALID_SOCKET == sockconn )
{
printf(“acc err\n“);
WSACleanup( );
Sleep(SLEEPMS);
return;
}
char sendData[SEND_MAX_LENGTH];
memset(sendData 0 SEND_MAX_LENGTH);
sprintf(sendData“%s““hello sender i\‘m receiver“);
if( SOCKET_ERROR == send(sockconnsendDatastrlen(sendData)+10) )
{
printf(“send welcome err\n“);
WSACleanup( );
closesocket(sockconn);
Sleep(SLEEPMS);
return;
}
char getData[RECEIVE_MAX_LENGTH];
memset(getData 0 RECEIVE_MAX_LENGTH);
recv(sockconngetDataRECEIVE_MAX_LENGTH0);
printf(“%s\n“getData);
printf(“1bit滑动窗口协议:接收方,接收窗口=1\n“);
linkQueue QueueQ;
InitLine(&QueueQ);
frame packetreceive; //data
frame packetsend; // acknak
//初始化接收窗口
int curw = GetframeFromHost(&QueueQ);
int ret = 0;
while(1)
{
//接收数据帧
memset(&packetreceive 0 sizeof(packetreceive));
Sleep(SLEEPMS);
printf(“\n“);
ret = recv(sockconn(char *)&packetreceive sizeof(packetreceive) 0);
if(ret == SOCKET_ERROR || ret == SOCKET_DISCONN)
{
if(ret == SOCKET_ERROR)
{
cprintf(“recv err! Auto continue\n“);
//while (!kbhit()) { /* do nothing */ };
continue;
}
else
{
cprintf(“连接已断开,按q退出,其他键等待新的连接\n“);
//while (!(kbc = kbhit())) { /* do nothing */ };
int kbc = getch();
if(kbc == ‘q‘ || kbc == ‘Q‘)
break;
else
{
WSACleanup( );
closesocket(sockconn);
Sleep(SLEEPMS);
goto Begin;
}
}
}
srand((unsigned)time(NULL));
switch(rand() % 5) //假定产生随机结果,20%的概率校验错误或接收发送方超时
{
case 0:
printf(“frame received: %d %d,校验错误\n“ packetreceive.h
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 83968 2010-04-16 19:09 实验一.doc
文件 48640 2010-04-05 20:26 SlideWindowSender\SlideWindowSender.opt
文件 1975296 2010-04-05 20:21 SlideWindowSender\Bin\SlideWindowSender.bsc
文件 1011 2010-04-04 23:26 SlideWindowSender\Src\common.h
文件 5340 2010-04-06 13:40 SlideWindowSender\Src\Sender.cpp
文件 1709 2010-04-03 23:38 SlideWindowSender\Src\SliderWindow.cpp
文件 1630 2010-04-05 20:21 SlideWindowSender\SlideWindowSender.plg
文件 540 2010-04-02 21:12 SlideWindowSender\SlideWindowSender.dsw
文件 58368 2010-04-05 20:26 SlideWindowSender\SlideWindowSender.ncb
文件 4609 2010-04-03 12:11 SlideWindowSender\SlideWindowSender.dsp
文件 48640 2010-04-05 20:20 SlideWindowReceiver\SlideWindowReceiver.opt
文件 4653 2010-04-03 22:08 SlideWindowReceiver\SlideWindowReceiver.dsp
文件 66560 2010-04-05 20:20 SlideWindowReceiver\SlideWindowReceiver.ncb
文件 1975296 2010-04-05 20:19 SlideWindowReceiver\Bin\SlideWindowReceiver.bsc
文件 1198 2010-04-05 00:12 SlideWindowReceiver\Src\common.h
文件 6398 2010-04-05 00:19 SlideWindowReceiver\Src\Receiver.cpp
文件 2545 2010-04-05 01:28 SlideWindowReceiver\Src\SliderWindow.cpp
文件 1654 2010-04-05 20:19 SlideWindowReceiver\SlideWindowReceiver.plg
文件 544 2010-04-03 00:04 SlideWindowReceiver\SlideWindowReceiver.dsw
文件 200789 2010-04-05 20:19 SlideWindowReceiver.exe
文件 196689 2010-04-05 20:21 SlideWindowSender.exe
文件 169984 2010-04-05 20:59 实验一:实验报告.doc
目录 0 2010-04-02 20:25 SlideWindowSender\Bin
目录 0 2010-04-02 20:26 SlideWindowSender\Src
目录 0 2010-04-02 20:17 SlideWindowReceiver\Bin
目录 0 2010-04-02 20:18 SlideWindowReceiver\Src
目录 0 2010-04-02 20:25 SlideWindowSender
目录 0 2010-04-02 20:15 SlideWindowReceiver
----------- --------- ---------- ----- ----
4856061 28
............此处省略1个文件信息
评论
共有 条评论