freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

文件傳輸協(xié)議的c語言實(shí)現(xiàn)-文庫吧

2025-05-15 22:04 本頁面


【正文】 /***********************************************************************函數(shù)名:main說明: 主函數(shù)輸入?yún)?shù): int argc 輸入?yún)?shù)長度 char *argv[]輸入?yún)?shù),用于傳入監(jiān)聽端口號(hào)***********************************************************************/int main(int argc, char *argv[]) { struct sockaddr_in SLocalAddr。 SOCKET h_Socket4Lstn。 //欲用作監(jiān)聽的socket int addr_in_len。//地址長度 //初始化winsock if (WSAStartup(MAKEWORD(2,2), amp。wsd) != 0) { WSACleanup()。 printf(WSAStartup failed\n)。 } memset(amp。SLocalAddr,0,sizeof(SLocalAddr))。 //創(chuàng)建socket h_Socket4Lstn = socket(PF_INET, SOCK_STREAM, 0)。 if (h_Socket4Lstn 0) printf(creating socket failed\n)。 = AF_INET。 if(argc == 2) = htons((u_short)atoi(argv[1]))。 else = htons(DEFAULT_LSTN_PORT)。 = INADDR_ANY。 //綁定socket if (bind(h_Socket4Lstn,(struct sockaddr *)(amp。SLocalAddr),sizeof(SLocalAddr)) 0) printf(Bind failed!\n)。 while (1) { //主循環(huán) listen(h_Socket4Lstn,3)。 //啟動(dòng)監(jiān)聽 addr_in_len = sizeof(RemoteAddr)。 //接受連接請求 h_NewSocket = accept( h_Socket4Lstn, (struct sockaddr *) (amp。RemoteAddr) , amp。addr_in_len)。 if (h_NewSocket == INVALID_SOCKET) break。//出錯(cuò)退出 printf(%s is connected at port %d \n,inet_ntoa(), ntohs())。 sprintf(SendBuffer,200 Wele \r\n)。 //向客戶端發(fā)送歡迎消息 bytes = send(h_NewSocket, SendBuffer, strlen(SendBuffer), 0)。 sprintf(SendBuffer,530 Log in \r\n)。 bytes = send(h_NewSocket, SendBuffer, strlen(SendBuffer), 0)。 while (1) { //接收客戶端的命令并調(diào)用命令處理函數(shù) n = 0。 iSynError=1。 while (1) { bytes = recv(h_NewSocket, amp。RecvBuffer[n], 1, 0)。 if ((bytes 0) || (bytes == 0)) break。 if (RecvBuffer[n] == 39。$39。) { RecvBuffer[n] = 39。\039。 break。 } if (RecvBuffer[n] != 39。\r39。) n++。 } if ((bytes 0) || (bytes == 0)) break。 printf(The Server received: 39。%s39。 cmd from client \n, RecvBuffer)。 //命令識(shí)別 //查看當(dāng)前目錄 if(strncmp(RecvBuffer,dir,3)==0) sdirfun(h_NewSocket)。 //查詢當(dāng)前目錄路徑 if(strncmp(RecvBuffer,pwd,3)==0) spwdfun(h_NewSocket)。 //改變當(dāng)前目錄 if (strncmp(RecvBuffer,cd,2)==0) scdfun(h_NewSocket)。 //文件下載 if (strncmp(RecvBuffer,get,3)==0) sgetfun(h_NewSocket)。 //文件上傳 if (strncmp(RecvBuffer,put,3)==0) sputfun(h_NewSocket)。 //新建文件夾 if (strncmp(RecvBuffer,md,2)==0) smdfun(h_NewSocket)。 //刪除文件 if (strncmp(RecvBuffer,del,3)==0) sdelfun(h_NewSocket)。 if (strncmp(RecvBuffer,quit,4)==0) //退出命令 { printf(quit \n)。 sprintf(SendBuffer, 221 Bye bye ... \r\n)。 bytes = send(h_NewSocket, SendBuffer, strlen(SendBuffer), 0)。 iSynError=0。 break。 } if (iSynError==1) //Syntax error { printf(mand unrecognized, nonimplemented!\n)。 sprintf(SendBuffer, 500 Syntax error. \n)。 bytes = send(h_NewSocket, SendBuffer, strlen(SendBuffer), 0)。 } } closesocket(h_NewSocket)。 printf(%s disconnected from port %d, control socket is closed.\n, inet_ntoa(),ntohs())。 } closesocket(h_Socket4Lstn)。 //釋放監(jiān)聽的socket return 0。}/***********************************************************************函數(shù)名:sdirfun說明: 用于處理來自客戶端的目錄查詢命令輸入?yún)?shù): SOCKET h_NewSocket,命令通過此socket接收到,可通過它響應(yīng)命令。**********************************************************************/int sdirfun(SOCKET h_NewSocket){ char temp_buffer[80]。 FILE *p_FiLeTemp。 //整理本地dir命令 strObject[0]=39。\039。 strcat(strObject,dir )。 strcat(strObject,path)。 strcat(strObject, )。 system(strObject)。 //system函數(shù)執(zhí)行shell命令 p_FiLeTemp=fopen(,r)。 //打開執(zhí)行結(jié)果文件,準(zhǔn)備發(fā)送到客戶端 sprintf(SendBuffer, 125 Transfering... \r\n)。 bytes = send(h_NewSocket, SendBuffer, strlen(SendBuffer), 0)。 while (fgets(temp_buffer,80,p_FiLeTemp)!=NULL) //每次讀取80字
點(diǎn)擊復(fù)制文檔內(nèi)容
公司管理相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1