【正文】
ar oa_add[11]。//發(fā)送協(xié)議頭結(jié)構(gòu)體變量 data user_data。 TCP建立連接之后,通信雙方都同時可以進行數(shù)據(jù)的傳輸, 其次,他是全雙工的;在保證可靠性上,采用超時重傳和捎帶確認機制 。 在 多 線 程 訪 問 臨 界 資 源 時 , 要 使 用 到 互 斥 所 進 行 加 鎖 , 用 到pthread_mutex_init()來初始化一個鎖, pthread_mutex_lock()來對臨界資源來進行加鎖, pthread_nutex_unlock 來對加鎖的資源解鎖,最后還要用到pthread_mutex_destory()來對鎖的銷毀和資源的釋放。 Sonsever 需求,二級服務(wù)器需要可以實現(xiàn)同號碼段 client 信息的轉(zhuǎn)發(fā), 當收到不是自己號碼段的 client 信息時,需要把信息轉(zhuǎn)發(fā)給一級服務(wù)器,然后通過一級服務(wù)把信息轉(zhuǎn)發(fā)給 client 所在的二級服務(wù)器,這樣來實現(xiàn)不同號碼段client 端的信息之間的交互。 N 轉(zhuǎn)發(fā) TCP 連接 TCP 連接 TCP 連接 Y 查詢 TCP 連接 轉(zhuǎn)發(fā) 轉(zhuǎn)發(fā) 信息 Y N 圖 5 系統(tǒng)工作流程圖 如圖 5 所示是系統(tǒng)大致的框架和功能示意圖。 all_address[geshu].fd = cfd。 這是處理來自二級服務(wù)器的 轉(zhuǎn)發(fā)請求,通多號碼段的匹配吧信息轉(zhuǎn)發(fā)給對應(yīng)的二級服務(wù)器上,實現(xiàn)信息的交互。 SPORT = atoi(argv[2])。 = htons(SPORT)。 } = AF_INET。當用戶不在數(shù)組里的時候,信息就會自動的丟棄了,并提示找不到用戶。 send([i].fd,amp。 printf(\n***zhuan fa to %s server ****\n,)。 fflush(stdin)。send_msg,cli_num,cli_msg)。 } break。 staff_print_(argv[6])。 MSG *buf = NULL。recv_msg)。 buf = NULL。 printf(\n***zhuan fa to %s server ****\n,)。 n = recv(,amp。 } } 130 二級服務(wù)器接收到一級服務(wù)器的信息時,就會通過號碼的匹配吧信息發(fā)給 13011 這個客戶端,實現(xiàn)了夸號碼段轉(zhuǎn)發(fā)。 strcpy(ss,)。 } } 圖 13 收信息運行圖 16 如圖 13 所示是查看收信箱的信息,其中調(diào)用了 recv_print_(argv[4])函數(shù)把儲存在文件中的短信信息多打印在終端上,可以顯示短信的發(fā)送者號碼和發(fā)送時間和具體的短信內(nèi)容。 if(NULL == fp) { printf(open fail !)。 } for(j = 0。如果 程序員 不能及時 的 將 這些錯誤 找出 來 并修改, 有可能 會 造成系統(tǒng)無法正常工作造 成 一些損失 。在這幾個月當中多是利用晚上的時間去編寫程序的,在編寫程序的過程中也遇到很多的苦難,用對一些知識還不是很熟,用起來會出現(xiàn)一些錯誤,但是最終通過網(wǎng)絡(luò),通過指導(dǎo)老師還是把這些問題給解決了。 參考文獻 [1]趙敏哲 .64 位 Linux 操作系統(tǒng)與應(yīng)用實例 [M].北京:機械工業(yè)出版社 ,20xx. [2]龐麗萍 .操作系統(tǒng)原理 (3 版 )[M].武漢:華中科技大學出版社 ,20xx. [3]張饒學 .Linux 網(wǎng)絡(luò)編程 [M].北京 :清華大學出版社 ,20xx. [4]金鐘夫 ,杜剛 .淺析 socket 網(wǎng)絡(luò)編程 [J].微計算機信息 ,20xx,32,8789. [5]鄭燕飛 ,余海燕 .linux 的多線程機制探討與實踐 [J].計算機應(yīng)用 ., 21(1):8182 [6]王群 ,許中萬 .Linux 優(yōu)勢分析 [J].計算機與現(xiàn)代化, 20xx(10):78. [7]任泰明著 . TCP/IP 協(xié)議與網(wǎng)絡(luò)編程 [M]. 西安 :西安電子科技大學出版社 . 20xx. [8]謝希仁 . 計算機網(wǎng)絡(luò)( 5 版) [M]. 西安 :電子工業(yè)出版社 . [9]陳劍 .基于 socket 的進程間通信平臺的設(shè)計與實現(xiàn) [D].東北大學 .20xx. [10]趙穎 ,韓秀梅,馬宏騫 .linux 下的 c 語言編程 [J].遼林工學院學報 . [11]陳波 ,石旭剛,史故臣 .嵌入式 c 語言在系統(tǒng)開發(fā)中的代碼優(yōu)化 [J].計算機時代 .20xx,( 11): 5556. 19 英文摘要 Design and implementation of SMS Linux transceiver system based on C Student majoring in puter science and technology Qin ZhangYang Tutor Liu Bin Abstract: The messaging system is Linux under the C language, based on multithreading, GMS protocol, select non blocking, using TCP connection and transmission mode and work programming. I want to do is to simulate the mobile phone short message form to send and receive SMS, a server to manage multiple service level to two, then the two stage management server to multiple clients, through the design of two layer load balancing server to realize the server, so the same number section number can be achieved the client message through the number of segments of two level servers to send and receive information, different numbers of transmit information through a mail client server, through the implementation of this system can be used to learn the knowledge link, consolidate and enhance the ability of their own programming. Keywords: C/S。 Send and receive text messages。因為自己知識體系還不是特別的完整,編程能力也沒有特別的強,所以系統(tǒng)并沒有那么的完善,所以在以后的工作中還是要繼續(xù)的學習,提升自己的編程能力和分析問題的能力。所以 要通過測試 ,盡 量的減少程序中 的錯誤, 從而 達到 系統(tǒng)穩(wěn)定運作的目的 ,使 短信收發(fā)系統(tǒng)工作不會收到影響 。j++) { leng = j + 1。 } while(1) { memset(amp。 int j。 strcpy(,)。 int i。 if(n = 0) { printf(sonser %s exit\n,)。one_scli,sizeof(msg),0)。 13111client send()函數(shù)把信息發(fā)給 131 二級服務(wù)器。recv_msg,argv[4])。 buf = (MSG *)malloc(sizeof(MSG))。 case 5: return。 recv_print_(argv[4])。send_msg,sizeof(submit),0)。