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

正文內(nèi)容

嵌入式課程設(shè)計(jì)(編輯修改稿)

2024-07-14 16:11 本頁面
 

【文章內(nèi)容簡介】 通過TCP方式建立連接,使用的通訊函數(shù)接口為套接字,套接字在網(wǎng)絡(luò)編程中有著舉足輕重的地位。通過本次課程設(shè)計(jì),我們創(chuàng)建TCP服務(wù)器線程,響應(yīng)多個(gè)客戶端的連接,讀取隊(duì)列/數(shù)組,向客戶端發(fā)送指定“學(xué)號”的數(shù)據(jù);創(chuàng)建TCP客戶端接收線程,連接服務(wù)器并請求指定“學(xué)號”的數(shù)據(jù),接收數(shù)據(jù)并存儲在文件中;在實(shí)現(xiàn)的這個(gè)過程中,利用數(shù)據(jù)結(jié)構(gòu)中的隊(duì)列構(gòu)造了數(shù)據(jù)表,方便程序訪問,同時(shí),也方便服務(wù)器端對數(shù)據(jù)的管理。通過本次課程設(shè)計(jì),掌握了Linux下的編程模式和編程方法,熟悉了Linux的基本操作;同時(shí),掌握了開發(fā)環(huán)境的搭建,常用的軟件服務(wù)的安裝,鍛煉了實(shí)際的工程能力;通過多線程編程方法,理解了線程和進(jìn)程的區(qū)別和聯(lián)系,掌握了創(chuàng)建線程和注銷線程的方法;通過對套接字的使用,掌握了在Linux下基于套接字的網(wǎng)絡(luò)編程,理解了Linux下套接字編程在服務(wù)器端和客戶端的編程流程,了解了網(wǎng)絡(luò)模型,提高了解決問題的能力。 參考文獻(xiàn)[1] :機(jī)械工業(yè)出版社,[2] :機(jī)械工業(yè)出版社,[3] :清華大學(xué)出版社,[4] :清華大學(xué)出版社,[5] :清華大學(xué)出版社, 附錄一 服務(wù)器端程序/********************************************文件名: 文件描述: 嵌入式課程設(shè)計(jì)程序完成日期:2017年9月8日作者:陳凱聯(lián)系方式:975500487@********************************************/include include sys/include sys/include arpa/include include include includesys//*函數(shù)申明*/void writer_function(void)。void serverThreadProc(void *)。//鏈表結(jié)點(diǎn)結(jié)構(gòu)體typedef struct _CLIENT_INFO_{ char szClientIp[16]。 int nClientPort。 int nClientSock。 struct _CLIENT_INFO_ *pNext。 struct _CLIENT_INFO_ *pPre。}CLIENT_INFO。/*數(shù)據(jù)類型*/typedef struct datatype { unsigned char number。 unsigned char age。 unsigned char high。 unsigned char weigh。 long time。 char *name。}Datatype。/****協(xié)議包結(jié)構(gòu)****/typedef struct pro_package{ char head。 //開始標(biāo)志為 設(shè)定為0x7E 1 int lenth。 //包的數(shù)據(jù)部分長度 4 unsigned char flag。 //0 : cmd 1:data 1 unsigned char stop。 //0 stop 1:send 1 unsigned char num。 //標(biāo)明發(fā)送信息 1 unsigned char data[200]。 //數(shù)據(jù)部分 }Pro_package。/*創(chuàng)建緩存區(qū)*/typedef struct queue{ Datatype buffer[5]。 int b_tail。 int b_head。}queue。 /*初始化隊(duì)列*/queue Queue = { .b_tail = 0, .b_head = 0,}。/*數(shù)據(jù)初始化*/char *NAME[5] = {wuhao, chenkai,liumenglin,liujin,liufeng}。unsigned char AGE[5] = {20,21,22,23,24}。unsigned char NUM[5] = {1,2,3,4,5}。unsigned char HIGH[5] = {175,174,173,175,165}。unsigned char WIGHT[5] = {58, 55, 62, 63, 50}。Datatype information[5]。/****全局變量***/int nListenSock =1。 //server lisen socketint nThreadFlag =0。 // thread start/stop flagCLIENT_INFO *pClientHead=NULL。 //client list headerstruct timeval sys_time。pthread_mutex_t mutex。int buffer_has_item=0。//主函數(shù)void main(void){ /**************子線程相關(guān)*******************/ pthread_t reader = 1。 //read進(jìn)程的進(jìn)程號 pthread_mutex_init(amp。mutex,NULL)。 //初始化 互斥鎖 /*初始化數(shù)據(jù)*/ int i = 0。 for(i=0。 i5。 i++) { information[i].name = NAME[i]。 information[i].age = AGE[i]。 information[i].number = NUM[i]。 information[i].high = HIGH[i]。 information[i].weigh = WIGHT[i]。 } /*創(chuàng)建線程,產(chǎn)生數(shù)據(jù)*/ pthread_create(amp。reader,NULL,(void*)amp。writer_function,NULL)。 /************主線程相關(guān)**********************/ //創(chuàng)建socket nListenSock =socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)。 if(nListenSock0) { printf(create listen socket error\n)。 return。 } //設(shè)置socket選項(xiàng) int nValue=1。 if(setsockopt(nListenSock,SOL_SOCKET, SO_REUSEADDR,(char*)amp。nValue,sizeof(int))0) { printf(set option SO_REUSEADDR fail!\n)。 close(nListenSock)。 return。 } //綁定 struct sockaddr_in localAddr。 memset(amp。localAddr,0x0,sizeof(localAddr))。 =AF_INET。 =htonl(INADDR_ANY)。 =htons(10000)。 if(bind(nListenSock,(struct sockaddr*)amp。localAddr,sizeof(struct sockaddr))0) { printf(bind liste sock fail!\n)。 close(nListenSock)。 return。 } //監(jiān)聽 if(listen(nListenSock,5)0) { printf(listen error!\n)。 close(nListenSock)。 return。 } //創(chuàng)建客戶端的線程 int nSrvThreadId =1。 nThreadFlag =1。 if(pthread_create((pthread_t*)amp。nSrvThreadId,NULL,(void*)amp。serverThreadProc,NULL)0) { printf(create server thread fail!\n)。 close(nListenSock)。 return。 } //等待退出 while(1) { if(pthread_join(nSrvThreadId,NULL)!=0) { return。 } } }/*處理客戶端函數(shù)*/void serverThreadProc(void *pPram){ int nMaxFd。 fd_set rset,allset。 struct timeval timeOut={0,20*1000}。 FD_ZERO(amp。allset)。 FD_SET(nListenSock,amp。allset)。 nMaxFd =nListenSock。 CLIENT_INFO *pTcpClient。 int nSelectR。 struct sockaddr_in clientAddr。 CLIENT_INFO *pTempClient。 unsigned char ucRcvBuf[100]。 int nAddrSize =sizeof(clientAddr)。 Pro_package package。 //定義包結(jié)構(gòu) unsigned char send_buffer[200]。 //發(fā)送緩存 int verify_flag = 0。 while(1) //while 循環(huán) { rset =allset。 nSelectR =select(nMaxFd+1,amp。rset,NULL,NULL,amp。timeOut)。 if(nSelectR==1) //若發(fā)生錯(cuò)誤 { continue。 } else if(nSelectR==0) //超時(shí) { continue。 } if(FD_ISSET(nListenSock,amp。rset)) // 檢查nListenSock是否在套接字集合中 { printf(a
點(diǎn)擊復(fù)制文檔內(nèi)容
規(guī)章制度相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1