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

正文內(nèi)容

基于linux網(wǎng)絡(luò)聊天室的設(shè)計3-資料下載頁

2025-06-18 16:47本頁面
  

【正文】 } = AF_INET。 = htons(MYPORT)。 = INADDR_ANY。 bzero(amp。(),8)。 if(bind(sockfd,(struct sockaddr*)amp。my_addr,sizeof(struct sockaddr)) == 1){ perror(bind)。 exit(1)。 } if(listen(sockfd,BACKLOG) == 1){ perror(listen)。 exit(1)。 } if((pthread_create(amp。accthread,NULL,(void *)acceptconnect,NULL)) != 0){ printf(Create thread error!\r\n)。 exit(1)。 } while(1){ char msg[MAXDATASIZE]。 scanf(%s,msg)。 if(send(new_fd,msg,strlen(msg),0) == 1){ perror(send)。 close(new_fd)。 exit(1)。 } if(strcmp(msg,exit) == 0){ printf(Byebye!\n)。 close(new_fd)。 close(sockfd)。 exit(1)。 } } return 0。}(2) 客戶端源程序清單如下,includeincludeincludeincludeincludeincludesys/includenetinet/includesys/includedefine PORT 3490define MAXDATASIZE 1024int sockfd。pthread_t recthread。void recmessage(void){ while(1){ int numbytes。 char buf[MAXDATASIZE]。 if((numbytes = recv(sockfd,buf,MAXDATASIZE,0)) == 1){ perror(recv)。 exit(1)。 } buf[numbytes]=39。\039。 if(strcmp(buf,exit) == 0){ printf(Server is closed\n)。 close(sockfd)。 exit(1)。 } printf(Server:%s\n,buf)。 }}int main(int argc,char *argv[]){ struct hostent *he。 struct sockaddr_in their_addr。 if(argc != 2){ fprintf(stderr,usage:client hostname\n)。 exit(1)。 } if((he=gethostbyname(argv[1])) == NULL){ herror(gethostbyname)。 exit(1)。 } if((sockfd = socket(AF_INET,SOCK_STREAM,0)) == 1){ perror(socket)。 exit(1)。 } = AF_INET。 = htons(PORT)。 = *((struct in_addr *)heh_addr)。 bzero(amp。(),8)。 if(connect(sockfd,(struct sockaddr *)amp。their_addr,sizeof(struct sockaddr)) == 1){ perror(connect)。 exit(1)。 } if((pthread_create(amp。recthread,NULL,(void *)recmessage,NULL))!=0){ printf(Create thread error!\r\n)。 exit(1)。 } while(1){ char msg[MAXDATASIZE]。 scanf(%s,msg)。 if(send(sockfd,msg,strlen(msg),0) == 1){ perror(send)。 close(sockfd)。 exit(1)。 } if(strcmp(msg,exit) == 0){ printf(Byebye!\n)。 close(sockfd)。 exit(1)。 }} return 0。}4 運行效果程序測試環(huán)境:linux、unix、debian等操作系統(tǒng)。測試軟件:putty、vmware虛擬機(jī)(1) ,用 gcc –lpthread –o server 生成程序server。(2) ,用gcc –lpthread –o client 生成程序client(3) 在主機(jī)上打開一窗口,運行server。(4) 再打開另一個窗口或者在另一個主機(jī)上打開一個窗口,運行client,輸入服務(wù)器的IP地址,并檢查器結(jié)果的正確性。輸入:【主】 ./server【從】 ./client () 輸出:【主】server:got connection from (5) 客戶端、服務(wù)器端窗口之間以及交錯發(fā)送信息的方式相互發(fā)送和接收信息。1) 客戶端、服務(wù)器端窗皆通過鍵盤輸入消息內(nèi)容平回車,以發(fā)送消息給對方;2) 消息中若使用空格,則作為本條消息結(jié)束及下一條消息的開始;3) 輸入exit則推出運行。開始運行后,服務(wù)器端窗口的執(zhí)行順序為:1) 鍵入“Hello,world!”發(fā)送給客戶端2) 接收客戶端發(fā)來的兩個消息;3) 鍵入“OK!”發(fā)送個客戶端;4) 輸入exit結(jié)束。服務(wù)器端運行結(jié)果如實驗圖41所示。圖41 服務(wù)器端窗口開始運行后,客戶端窗口的執(zhí)行順序為:1) 接收服務(wù)器端發(fā)來的消息“Hello,world!”。2) 發(fā)送消息“hello!“和”Good!”給服務(wù)器端;3) 接收服務(wù)器發(fā)來的消息“OK!”。4) 鍵入exit結(jié)束??蛻舳诉\行結(jié)果如實驗圖42所示。圖42 客戶端窗口上述運行結(jié)果表明,客戶端與服務(wù)器端之間傳遞的消息已被對方成功接收。
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1