Login
升级VIP 登录 注册 安全退出
当前位置: 首页 > word文档 > 合同模板 > 停等协议,停等协议的信道利用率

停等协议,停等协议的信道利用率

收藏

本作品内容为停等协议,格式为 doc ,大小 62464 KB ,页数为 6页

停等协议


('网络实验报告(二)——停--等协议一、实验目的:1.利用VB模拟停--等协议。2.了解协议内容并模拟传输过程,掌握停--等协议的实现方法。二、实验环境:硬件环境:P41.6G.128MSDRAM。系统环境:Windows98操作系统。开发环境:MicrosoftVisualBasic6.0中文版。模拟环境:点到点的面向链接的通信。三、桢格式:桢头数据桢尾注:帧头与帧尾均为字符串“DLESTX”。对将要发送的数据使用split()函数,以空格为标志进行分割,把数据分成以单词为单位的字符串数组,每次读取一个字符串。以帧头+空格+数据+空格+帧尾为顺序组帧。分帧时使用split()函数,以空格为标志,把数据帧分解成字符串数组,读出数据,完成组帧。四、程序流程图:1/6五、编程原理及思路:由于接收缓冲只能存放一个帧且接收端需要一定的处理时间。为了防止发送快于接收而导致数据丢失,限制发送端在发送一帧后必须停止发送,等待接收端发确认帧。而接收端在收到一个数据帧并发送网络层后,向发送端发一确认帧。仅当接收方确认正确接收后再继续发送下一帧。六、程序源代码(VB):注:此程序的接收端和发送端是同一个程序的不同运行模式。frmMain.frm:Privateg_bConfirmAsBoolean\'发送一帧后设置为False,收到后设置为TruePrivateSubcmdReceiverListen_Click()\'检查错误IfVal(txtReceiverPort.Text)=0ThenMsgBox"PleaseInputPortNumber!",vbInformation,"ERROR"ExitSubEndIf\'开始监听WithsckReceiver.LocalPort=Val(txtReceiverPort.Text).ListenEndWith\'显示信息ShowInfo"Listeningat:"&sckReceiver.LocalIP&"Port:"&2/6FT服务器端(接收端)客户端(发送端)开始开始开始监听接受连接请求连接服务器准备数据并分桢显示数据接收数据并发确认桢按桢发送数据数据结束?结束txtReceiverPort.TextcmdReceiverListen.Enabled=FalseEndSubPrivateSubShowInfo(ByValsInfoAsString)\'显示信息到列表lstInfo.AddItem(sInfo)lstInfo.ListIndex=lstInfo.ListCount-1EndSubPrivateSubcmdSenderConnect_Click()\'连接IfcmdSenderConnect.Caption="&Connect"ThenIftxtSenderHostIP.Text=""OrtxtSenderPort.Text=""ThenMsgBox"InvalidIPaddress/portnumberinput.",vbCritical,"ERROR"ExitSubEndIfWithsckSender.RemoteHost=txtSenderHostIP.Text.RemotePort=Val(txtSenderPort.Text).ConnectShowInfo"ConnectTo:"&.RemoteHost&"Port:"&.RemotePortEndWithcmdSenderConnect.Caption="Dis&connect"cmdSenderSend.Enabled=TrueElseShowInfo"TerminationOfConnectionTo:"&sckSender.RemoteHost&"Port:"&sckSender.RemotePortsckSender.ClosecmdSenderConnect.Caption="&Connect"cmdSenderSend.Enabled=FalseEndIfEndSubPrivateSubcmdSenderSend_Click()\'发送文字DimvOutAsVariantDimlLoopAsLongg_bConfirm=TruevOut=modFrame.ToFrame(txtSenderMessage.Text)ShowInfo"SendingMessageTo:"&sckSender.RemoteHostIP&"With"""&txtSenderMessage.Text&""""ForlLoop=0ToUBound(vOut)\'循环输出帧3/6WhileNotg_bConfirmDoEvents\'等待Wend\'能够发送g_bConfirm=FalseDebug.PrintvOut(lLoop)DimsOutAsStringsOut=vOut(lLoop)sckSender.SendDatasOutNextEndSubPrivateSubForm_Load()tabMain_ClickEndSubPrivateSubsckReceiver_ConnectionRequest(ByValrequestIDAsLong)\'得到连接请求WithsckReceiver.Close.AcceptrequestIDShowInfo"IncomingConnectionFrom:"&.RemoteHostIPEndWithEndSubPrivateSubsckReceiver_DataArrival(ByValbytesTotalAsLong)\'得到数据DimsInAsString\'收到字符串WithsckReceiver.GetDatasIn,vbStringDebug.Print"RECEIVING"&sIntxtReceiverMessage.Text=txtReceiverMessage.Text&""&modFrame.FromFrame(sIn)ShowInfo"IncomingMessage:"&.RemoteHostIP&"["&sIn&"]".SendData1EndWithEndSubPrivateSubsckSender_DataArrival(ByValbytesTotalAsLong)\'收到数据\'实际上就是收到确认帧的问题g_bConfirm=TrueEndSubPrivateSubtabMain_Click()4/6IftabMain.SelectedItem.Caption="As&Sender"ThenfmeSender.Visible=TruefmeReceiver.Visible=FalseElsefmeSender.Visible=FalsefmeReceiver.Visible=TrueEndIfEndSubPrivateSubtxtReceiverPort_GotFocus()\'得到焦点的时候选定字符txtReceiverPort.SelLength=Len(txtReceiverPort.Text)EndSubPrivateSubtxtReceiverPort_KeyPress(KeyAsciiAsInteger)\'不允许输入数字以外的字符IfKeyAscii<>8ThenIfKeyAscii>57OrKeyAscii<48ThenKeyAscii=0EndIfEndIfEndSubPrivateSubtxtSenderHostIP_KeyPress(KeyAsciiAsInteger)\'不允许输入数字以外,非“.”号的字符IfNot(KeyAscii=8OrKeyAscii=46)ThenIfKeyAscii>57OrKeyAscii<48ThenKeyAscii=0EndIfEndIfEndSubPrivateSubtxtSenderPort_GotFocus()\'得到焦点后选定字符txtSenderPort.SelLength=Len(txtSenderPort.Text)EndSubPrivateSubtxtSenderPort_KeyPress(KeyAsciiAsInteger)\'不允许输入数字以外的字符IfKeyAscii<>8ThenIfKeyAscii>57OrKeyAscii<48ThenKeyAscii=0EndIfEndIf5/6EndSubmodFrame.bas:PrivateConstFRAME_HEAD="DLESTX"PrivateConstFRAME_END="DLEETX"PublicFunctionFromFrame(ByValsInAsString)AsString\'输入帧,输出原始文字DimvInAsVariantvIn=Split(sIn,"")vIn(2)=Replace(vIn(2),"DLEDLE","DLE")FromFrame=vIn(2)EndFunctionFunctionToFrame(ByValsInAsString)AsVariant\'将字符串分帧\'输入数据是字符串,输出为从0开始的数组DimvFrameAsVariantDimlLoopAsLongvFrame=Split(sIn,"")\'以空格为标志,把数据分成以单词为单位的字符串数组ForlLoop=0ToUBound(vFrame)vFrame(lLoop)=Replace(vFrame(lLoop),"DLE","DLEDLE")vFrame(lLoop)=FRAME_HEAD&""&vFrame(lLoop)&""&FRAME_ENDNextToFrame=vFrameEndFunction七、心得体机会:觉得通过实验过程对停--协议有了更深刻的认识!6/6',)


  • 编号:1700667120
  • 分类:合同模板
  • 软件: wps,office word
  • 大小:6页
  • 格式:docx
  • 风格:商务
  • PPT页数:62464 KB
  • 标签:

广告位推荐

相关合同模板更多>