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

  • 大小: 1.4M
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-09-02
  • 語(yǔ)言: 其他
  • 標(biāo)簽: 其他??

資源簡(jiǎn)介

滑動(dòng)窗口協(xié)議.zip

資源截圖

代碼片段和文件信息

#include“socket_udp.h“
?
#define?HLEN?3//幀頭部長(zhǎng)度
#define?DLEN?8//幀數(shù)據(jù)長(zhǎng)度
#define?ALEN?3//ACK幀長(zhǎng)度
#define?SWP_SEND_TIMEOUT?500//定義超時(shí)長(zhǎng)度為500ms
#define?link?“127.0.0.1“//定義要發(fā)送的對(duì)象
#define?FLAG_ACK_VALID?‘a(chǎn)‘//定義ACK幀
#define?FLAG_DATA_VALID?‘d‘//定義數(shù)據(jù)幀
#define?SUCCESS?1;//定義已經(jīng)成功收到的消息
?
?
static?void?sendSWP(SwpState?*stateMsg?*frame);//發(fā)送函數(shù)
static?int?deliverSWP(SwpState?*stateMsg?*frame);//接收并返回ACK函數(shù)
?
//發(fā)送
static?void?semWait(Semaphore?*sendWindowNotFull);//信號(hào)量處理(-1)
static?void?store_swp_hdr(SwpHdr?hdrchar?*hbuf);//存儲(chǔ)發(fā)送的幀頭部
static?void?msgAddHdr(Msg?*framechar?*hbuf);//將頭部添加到幀上
static?void?msgSaveCopy(char?*msgMsg?*frame);//將消息添加到幀上
static?Event?evSchedule(Msg?*frameint?time);//調(diào)用定時(shí)器函數(shù)
DWORD?WINAPI?swpTimeout(LPVOID?threadtype);//創(chuàng)建定時(shí)器線程
static?void?send_socket(char?*addrMsg?*frameint?size);//UDP發(fā)送
static?void?mlisten();//監(jiān)聽(tīng)數(shù)據(jù)
static?void?msend();//發(fā)送數(shù)據(jù)
//接收
static?char?*msgStripHdr(Msg?*frameint?length);//獲取幀的頭部
static?void?load_swp_hdr(SwpHdr?*hdrchar?*hbuf);//幀頭部提取字符串
static?bool?swpInWindow(SwpSeqno?AckNumSwpSeqno?LARSwpSeqno?LFS);//判斷收到的幀是否在窗口內(nèi)
static?void?evCancel(Event?*);//取消超時(shí)定時(shí)器
static?void?msgDestroy(Msg?*msg);//釋放msg空間
static?void?semSignal(Semaphore?*sendWindowNotFull);//信號(hào)量處理(+1)
static?void?prepare_ack(Msg?*msgSwpSeqno?n);//組成ACK消息
?
//全局變量
HANDLE?hlisten;
HANDLE?hsend;
SwpState?*send_state;
Msg?*frame;
HANDLE?Mutex?=?CreateMutex(NULLFALSENULL);
?
void?main(){
//模擬滑動(dòng)窗口接收和發(fā)送過(guò)程
//初始化SwpStateMsg數(shù)據(jù)幀組幀
//啟動(dòng)兩個(gè)線程,模擬收發(fā)
//監(jiān)聽(tīng)終止
frame=(Msg?*)malloc(11*sizeof(Msg));
//初始化消息
//frame=“message“;//8個(gè)字節(jié)的數(shù)據(jù)
//初始化狀態(tài)
send_state=(SwpState?*)malloc(sizeof(SwpState));
send_state->LAR=‘0‘;
send_state->LFS=‘0‘;
send_state->NFE=‘0‘;
send_state->sendWindowNotFull=CreateSemaphore(NULLSWSSWSNULL);
if(send_state->sendWindowNotFull==NULL){
printf(“CreateSemaphore?error\n“GetLastError());
exit(0);
}
send_state->hdr.SeqNum=‘0‘;//3個(gè)字節(jié)頭部
send_state->hdr.AckNum=‘0‘;
send_state->hdr.Flags=‘d‘;
for(int?i=0;i send_state->sendQ[i].msg=(Msg?*)malloc(8*sizeof(Msg));
send_state->sendQ[i].msg=“message“;
send_state->sendQ[i].timeout=NULL;
}
for(i=0;i send_state->recvQ[i].msg=(Msg?*)malloc(8*sizeof(Msg));
send_state->recvQ[i].msg=“message“;
send_state->recvQ[i].recevied=NULL;
}
//初始化UDP函數(shù)
WSADATA?wsaData;
????if?(WSAStartup(MAKEWORD(21)&wsaData)){
printf(“Winsock?initializing?fail\n“);
????????WSACleanup();
????????return;
????}
//建立監(jiān)聽(tīng)線程
hlisten=CreateThread(NULL0(LPTHREAD_START_ROUTINE)?mlistenNULLCREATE_SUSPENDEDNULL);
ResumeThread(hlisten);
if(hlisten==NULL){
printf(“thread_listen?create?fail\n“);
}
hsend=CreateThread(NULL0(LPTHREAD_START_ROUTINE)?msendNULLCREATE_SUSPENDEDNULL);
ResumeThread(hsend);
if(hsend==NULL){
printf(“thread_send?create?fail\n“);
}
Sleep(10000);
????WSACleanup();
}
static?void?msend(){
printf(“thread_send?started\n“);
while(1){
sendSWP(send_stateframe);

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-10-31?19:00??Debug\
?????文件???????32204??2018-10-31?19:00??Debug\socket_udp.obj
?????文件??????148480??2018-10-31?19:00??Debug\vc60.idb
?????文件???????77824??2018-10-31?19:00??Debug\vc60.pdb
?????文件??????176171??2018-10-31?19:00??Debug\xieyi.exe
?????文件??????207796??2018-10-31?19:00??Debug\xieyi.ilk
?????文件?????3596772??2018-10-31?18:05??Debug\xieyi.pch
?????文件??????459776??2018-10-31?19:00??Debug\xieyi.pdb
?????文件????????9025??2018-10-31?18:59??socket_udp.cpp
?????文件????????1065??2018-10-31?18:05??socket_udp.h
?????文件????????4342??2018-10-31?19:17??xieyi.dsp
?????文件?????????516??2018-10-31?18:04??xieyi.dsw
?????文件???????33792??2018-10-31?19:17??xieyi.ncb
?????文件???????48640??2018-10-31?19:17??xieyi.opt
?????文件????????1360??2018-10-31?19:00??xieyi.plg

評(píng)論

共有 條評(píng)論