91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 8KB
    文件類型: .java
    金幣: 1
    下載: 1 次
    發(fā)布日期: 2021-06-14
  • 語言: Java
  • 標(biāo)簽: Go-Back-N??

資源簡介

運(yùn)用編程語言實(shí)現(xiàn)基于Go-Back-N 的可靠數(shù)據(jù)傳輸軟件

資源截圖

代碼片段和文件信息

//package?protocol;
import?java.net.*;
import?java.util.*;
import?java.io.*;

@SuppressWarnings(“unused“)
public?class?GBN?extends?Thread?{
static?void?senddelay(int?x?int?y)?throws?InterruptedException?{
if?(x?==?1)?{
sleep(300);
System.out.println(“發(fā)送數(shù)據(jù)分組“?+?y?+?“時(shí)發(fā)生延遲:300毫秒!“);
}?else?if?(x?==?2)?{
sleep(750);
System.out.println(“發(fā)送數(shù)據(jù)分組“?+?y?+?“時(shí)發(fā)生延遲:750毫秒!“);
}?else?if?(x?==?3)?{
sleep(1200);
System.out.println(“發(fā)送數(shù)據(jù)分組“?+?y?+?“時(shí)發(fā)生延遲:1200毫秒!“);
}?else?if?(x?==?4)?{
sleep(2500);
System.out.println(“發(fā)送數(shù)據(jù)分組“?+?y?+?“時(shí)發(fā)生延遲:2500毫秒!“);
}?else?if?(x?==?5)?{
sleep(3000);
System.out.println(“發(fā)送數(shù)據(jù)分組“?+?y?+?“時(shí)發(fā)生延遲:3000毫秒!“);
}?else
;
}

static?void?OutputWindow(Sender?s)?{
for?(int?k?=?0;?k? //?表示至少成功發(fā)送并確認(rèn)了一個(gè)數(shù)據(jù)分組
s.windowsign[k]++;
//?這種情況下滑動(dòng)窗口向前移動(dòng)!
}
System.out.println();
System.out.println(“當(dāng)前窗口內(nèi)的分組情況為:“);
//?顯示當(dāng)前窗口內(nèi)數(shù)據(jù)包情況
for?(int?p?=?0;?p? if?(s.windowsign[p]?<=?6)
if?(s.sent[s.windowsign[p]]?==?0)?{
System.out.println(“第“?+?p?+?“號窗口里面存放的是序號為“
+?s.windowsign[p]?+?“的待確認(rèn)的數(shù)據(jù)分組!“);
}?else
System.out.println(“第“?+?p?+?“號窗口里面存放的是序號為“
+?s.windowsign[p]?+?“的待發(fā)送的數(shù)據(jù)分組!“);
else
System.out.println(“第“?+?p?+?“號窗口已經(jīng)空了,并且后續(xù)窗口、發(fā)送方?jīng)]有要發(fā)送的數(shù)據(jù)分組了!“);
}
System.out.println();
}

public?static?void?main(String[]?args)?throws?IOException
InterruptedException?{
Sender?s?=?new?Sender();
Receiver?re?=?new?Receiver();
s.start();//?發(fā)送端啟動(dòng)
re.run(s);//?接收端啟動(dòng)
sleep(1000);//?延遲處理
for?(int?i?=?0;?i?<=?s.sign.length;?i++)?{
while?(i?>?s.localack?+?1)?{
//?尚有未確認(rèn)的數(shù)據(jù)包,重發(fā)!
System.out.println(“發(fā)送方開始重新發(fā)送序號為“?+?(s.localack?+?1)?+?“的數(shù)據(jù)分組“);
int?ran?=?new?Random().nextInt(4);
int?randelay?=?new?Random().nextInt(6);
s.time();
senddelay(randelay?s.localack?+?1);//?設(shè)置隨機(jī)值,模擬數(shù)據(jù)傳輸延遲
if?(ran?!=?1)?{
re.receive(s.localack?+?1?s);//?設(shè)置隨機(jī)值,模擬數(shù)據(jù)丟包的過程
if?(s.localack?>=?0)
if?(s.acksign[s.localack]?==?0)?{
if?(s.localack?+?3?<=?6)
s.sent[s.localack?+?3]?=?0;
OutputWindow(s);
}
}?else
System.out.println(“序號為“?+?(s.localack?+?1)
+?“的分組在傳給接收方途中發(fā)生了丟包!“);
}
if?(i?!=?s.sign.length)?{
if?(i?==?0)?{
System.out.println();
System.out.println(“發(fā)送方:現(xiàn)在發(fā)送序號為0-2的數(shù)據(jù)分組“);
s.sent[0]?=?0;
s.sent[1]?=?0;
s.sent[2]?=?0;
System.out.println();
int?ran1?=?new?Random().nextInt(4);
int?randelay1?=?new?Random().nextInt(6);
s.time();//?計(jì)時(shí)開始(2秒時(shí)間)
senddelay(randelay1?0);//?設(shè)置隨機(jī)值,模擬數(shù)據(jù)傳輸延遲
if?(ran1?!=?1)?{
re.receive(s.sign[0]?s);//?設(shè)置隨機(jī)值,模擬數(shù)據(jù)丟包過程
if?(s.acksign[0]?==?0)?{
s.sent[3]?=?0;
s.acknowledged[0]?=?0;
OutputWindow(s);
}
}?else
System.out.println(“序號為“?+?“0“?+?“的分組在傳給接收方途中發(fā)生了丟包!“);
i++;
int?ran2?=?new?Random().nextInt(4);
int?randelay2?=?n

評論

共有 條評論

相關(guān)資源