資源描述:
《windows socket編程實驗報告》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、深圳大學實驗報告課程名稱:計算機網(wǎng)絡(luò)實驗項目名稱:windowssocket編程學院:專業(yè):指導教師:報告人:學號:班級:實驗時間:2014.12.19實驗報告提交時間:2014.12.26教務(wù)處制實驗?zāi)康呐c要求:實驗?zāi)康氖煜ず驼莆誷ocket編程的基本理論和方法。掌握基于TCP和UDP的工作原理以及Socket編程的一般方法,能夠編寫簡單的網(wǎng)絡(luò)應(yīng)用程序。實驗要求采用無連接協(xié)議的異步模式,編寫服務(wù)端及客戶端應(yīng)用程序,實現(xiàn)兩者之前文字信息的傳輸。方法、步驟:分別建立兩個項目,server和client,在VC6.0-->新建->工程->
2、win32application->輸入項目名->選擇atypical"helloworld"win32application。并按照圖片中的要求添加代碼。2.調(diào)試程序。3.兩臺電腦實現(xiàn)鏈接。實驗過程及內(nèi)容:1.分別建立兩個項目,server和client,在VC6.0-->新建->工程->win32application->輸入項目名->選擇atypical"helloworld"win32application。并按照圖片中的要求添加代碼。2.調(diào)試程序。3.兩臺電腦實現(xiàn)鏈接。Server端//server.cpp:Definesth
3、eentrypointfortheapplication.//#include"stdafx.h"#include"resource.h"#defineMAX_LOADSTRING10000#include#pragmacomment(lib,"Ws2_32.lib")WSADATAws;SOCKETS;structsockaddr_inlAddr,rAddr;intLPort=6666;charLIP[]="0.0.0.0";charMsg[88];intd,l=sizeof(rAddr);voidSetSoc
4、kAddr(structsockaddr_in*A,WORDPort,char*IP){A->sin_family=AF_INET;A->sin_port=htons(Port);A->sin_addr.s_addr=inet_addr(IP);}TCHARmessageDisplay[MAX_LOADSTRING]=_T("");HWNDhSend;HWNDhText;//GlobalVariables:HINSTANCEhInst;//currentinstanceTCHARszTitle[MAX_LOADSTRING];//The
5、titlebartextTCHARszWindowClass[MAX_LOADSTRING];//Thetitlebartext//Fowarddeclarationsoffunctionsincludedinthiscodemodule:ATOMMyRegisterClass(HINSTANCEhInstance);BOOLInitInstance(HINSTANCE,int);LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);LRESULTCALLBACKAbout(HWND,UINT,
6、WPARAM,LPARAM);intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){//TODO:Placecodehere.MSGmsg;HACCELhAccelTable;//InitializeglobalstringsLoadString(hInstance,IDS_APP_TITLE,szTitle,MAX_LOADSTRING);LoadString(hInstance,IDC_SERVER,szWin
7、dowClass,MAX_LOADSTRING);MyRegisterClass(hInstance);//Performapplicationinitialization:if(!InitInstance(hInstance,nCmdShow)){returnFALSE;}hAccelTable=LoadAccelerators(hInstance,(LPCTSTR)IDC_SERVER);//Mainmessageloop:while(GetMessage(&msg,NULL,0,0)){if(!TranslateAccelerat
8、or(msg.hwnd,hAccelTable,&msg)){TranslateMessage(&msg);DispatchMessage(&msg);}}returnmsg.wParam;}////FUN