實驗報告與視頻-實驗一_第1頁
實驗報告與視頻-實驗一_第2頁
實驗報告與視頻-實驗一_第3頁
實驗報告與視頻-實驗一_第4頁
實驗報告與視頻-實驗一_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

實驗?zāi)空莆誄lient/Server結(jié)構(gòu)的設(shè)計與開發(fā)方掌握Socket實驗環(huán)編譯器實驗內(nèi)容與結(jié)果TCP/IP網(wǎng)絡(luò)環(huán)境下,不同主機上的兩個應(yīng)用程序通信Winsock的啟動和終止——WSAStaruop(和WSACleanup(創(chuàng)建套接字——socket()綁定本地地址——bind(偵聽連接——listen()建立套接字連接——accept()和connect()面向連接的數(shù)據(jù)傳輸——send()和recv()無連接的數(shù)據(jù)傳輸snedto()和recvfrom(輸入輸出多路復(fù)用——select())時間函數(shù)——GetLocalTime(WSAStaruop的函數(shù)如下intWSAStartup(WORDwVersionRequested,LPWSADATA的副版本,低位字節(jié)指定Winsock的主版本,然后用MAKEWORD(X,Y)宏獲 //WinsockWORDwHighVersion;WinsockcharszDescription[WSADESCRIPTION_LEN+1];//套接字實現(xiàn)描述unsignedshortiMaxSockets;最大套接字?jǐn)?shù)unsignedshortiMaxUdpDg;//最大數(shù)據(jù)報長度charFAR*IpVendorInfo;}WSADATA,FAR intSOCKETsocket(intaf,inttype,intaf:指定網(wǎng)絡(luò)地址族,一般為AF_INET。 protocol:指定網(wǎng)絡(luò)協(xié)議,一般為0,表示默認(rèn)的TCP/IP協(xié)intbind(SOCKETs,conststructsockaddtFAR*name,int參數(shù)說 namesockaddrnamelensockaddrsockddrTCP/IPstruct sin_family;//指定地址族,一般為AF_INET structin_addrsin_addr;//IP sin_zero[8IPin_addrin_addr{{struct{u_shorts_w1,s_w2;}S_un_w;u_longintlisten(SOCKETs,int 指定正在等待連接的隊列的最大長度,可取1~5。SOCKETaccept(SOCKETs,structsockaddrFAR*addr,intFAR*s:指定處于狀態(tài)的套接字句柄。 指定一個有效的SOCKADDR_IN結(jié)構(gòu)地址。addrlen:指定SOCKADDR_IN結(jié)構(gòu)的長度。accept函數(shù)返回后,addr變量中會包含請求連接的客戶IP地址,并返回 d(SOCKETs,constcharFAR*buf,intlen,intflagss:指定發(fā)送端套接字描 一般置0。intrecv(SOCKETs,charFAR*buf,intlen,intflagss:指定接收端套接字描*bufrecvlenbufflags:一般置0 dto(SOCKETs,constcharFAR*buf,intlen,intflags,conststructsockaddrFAR*to,inttolen;intrecvfrom(SOCKETs,charFAR*buf,intlen,intflags,structsockaddrFAR**from,intFAR*fromlen;intselect(intnfds,fd_setFAR*readfds,fd_setFAR*writefds,fd_setFAR*exceptfds,conststructtimevalFAR*timeout);nfds:本參數(shù)忽略,僅起到兼容作用 readfds:writefds(exceptfds(timeout:select()最多等待時間,對阻塞操作則為NULL。intclosesocket(socket程序(手寫或者打印后作為附件程序的運行和(提供截圖Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113實驗中的問題如遇到無法編譯的問題,經(jīng)過改正,發(fā)現(xiàn)codeblocks只有在主函數(shù)默認(rèn)為main.c情況下才會編譯成功,然后是sleep函數(shù),第一個S大寫才能通過。最后是附程序源代碼(只附主要部分代碼while len=recv(new_s,buf,sizeof(buf),/*wliucomments:modifiedtostopsending*/if(strlen(buf)==0) /*wliucomments:receivedemptymessage*/printf("[simplex-talkserver]emptymessageis}

elseprintf("[simplex-talkserver]received%d\n",fputs(buf,stdout); ACKto

}}if(strlen(buf)==1 /*wliucomments:userinputemptymessagewith

buf[0]=send(s,buf,1,printf("[simplex-talkclient]emptymessageissend}elsebuf[MAX_BUFSIZE-1]=len=strlen(buf)+1;send(s,buf,len,0); server\n",strlen(buf)); printf("NoAck\n"); server\n",strlen(buf)); }}while len=recv(new_s,buf,sizeof(buf),/*wliucomments:modifiedtostopsending*/if(strlen(buf)==0) /*wliucomments:receivedemptymessage*/printf("[simplex-talkserver]emptymessageis}elseprintf("[simplex-talkserver]received%d\n",fputs(buf,stdout); printf("sendACKto server]received%dchars\n",fputs(buf,stdout); }}if(strlen(buf)==1 /*wliucomments:userinputemptymessagewith

buf[0]=send(s,buf,1,printf("[simplex-talkclient]emptymessageissend}elsebuf[MAX_BUFSIZE-1]=len=strlen(buf)+1;send(s,buf,len,0);printf("[simplex- printf("NoAck\n"); server\n",strlen(buf)); }}while len=recv(new_s,buf,sizeof(buf),/*wliucomments:modifiedtostopsending*/if(strlen(buf)==0) /*wliucomments:receivedemptymessage}

printf("[simplex-talkserver]emptymessageiselseprintf("[simplex-talkserver]received%d\n",fputs(buf,stdout); ACKto

printf("[simplex-talkserver]received%dchars\n",fputs(buf,stdout); ACKto

}}if(strlen(buf)==1 /*wliucomments:use

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論