利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng).doc_第1頁
利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng).doc_第2頁
利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng).doc_第3頁
利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng).doc_第4頁
利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng).doc_第5頁
免費(fèi)預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng)XX 大 學(xué) 計(jì) 算 機(jī) 學(xué) 院、軟 件 學(xué) 院 實(shí) 驗(yàn) 報(bào) 告 學(xué)號(hào): 姓名: 專業(yè):軟件學(xué)院 班級(jí):09 第 3 周 課程名稱 信息安全產(chǎn)品開發(fā)實(shí)踐 實(shí)驗(yàn)課時(shí) 1 實(shí)驗(yàn)項(xiàng)目 遠(yuǎn)程控制系統(tǒng) 實(shí)驗(yàn)時(shí)間 2013/9/27 實(shí)驗(yàn)?zāi)康?流套接字與數(shù)據(jù)報(bào)套接字回顧 遠(yuǎn)程控制系統(tǒng)流程 實(shí)驗(yàn)環(huán)境 X86,Windows7,VMware9.0,Red Hat Enterprise Linux 5.0 實(shí)驗(yàn)內(nèi)容(算法、程序、步驟和方法) 利用流套接字實(shí)現(xiàn)一個(gè)簡單的遠(yuǎn)程控制系統(tǒng): 客戶端輸入“quit”,客戶端程序與服務(wù)器端程序打印退出信息,終止程序的執(zhí)行; 客戶輸入命令

2、,客戶端將命令通過流套接字發(fā)送給客戶端,服務(wù)器執(zhí)行收到的命令,并將結(jié)果發(fā)送到客戶端顯示; 如果沒有客戶輸入的命令,服務(wù)器發(fā)送命令非法信息,并在客戶端顯示該條信息。 編寫實(shí)驗(yàn)報(bào)告: 列出程序運(yùn)行狀態(tài)、截圖、配文字說明; 獨(dú)立完成,打印報(bào)告,報(bào)告語言為中文,不少于4頁A4,封面上書寫姓名、學(xué)號(hào)。 (接上) 實(shí)驗(yàn)內(nèi)容(算法、程序、步驟和方法) 修改代碼: 編譯 運(yùn)行結(jié)果: 源代碼: udpclient.c /* * = * * Filename: udpclient.c * * Description: : This program is used to demostrate how to impl

3、ement a udp rpc control server * * Version: 1.0 * Created: 2013騫?9鏈?5鏃?16鏃?6鍒?5縐? * Revision: none * Compiler: gcc * * Author: Gang liang * Organization: Computer Science College, Sichuan University * * = */ #include #include #include #include #include #define PORT 8888 #define SIZE 2048 #include /*

4、 * = FUNCTION = * Name: print_useage * Description: * = */ void print_usage (char* cmd ) fprintf(stderr,“Usage:%s ip addressn“,cmd); /* - end of function print_useage - */ /* * = FUNCTION = * Name: main * Description: * = */ int main ( int argc, char *argv ) int sockfd; struct sockaddr_in client; st

5、ruct sockaddr_in server; int len; int port; int rvalue; char bufferSIZE; char cmd10; /* these two vars used to deal with cd command */ /char path2028; /init sockfd=-1; bzero(&client,sizeof(struct sockaddr); bzero(&server,sizeof(struct sockaddr); len=-1; rvalue=-1; port=PORT; memset(buffer,0,sizeof(b

6、uffer); bzero(cmd,10); /bzero(path,2048); if (2!=argc) print_usage(argv0); exit(-1); /phrase 1: The creation of the socket sockfd=socket(AF_INET,SOCK_STREAM,0); if (-1=sockfd) fprintf(stderr,“error in creating socketn“); exit(-1); /Communation with the server.Attention:Client should send data to the

7、 server first. /Set the destinations address server.sin_family=AF_INET; server.sin_addr.s_addr=inet_addr(argv1); server.sin_port=htons(port); if (-1=connect(sockfd,(struct sockaddr*)&server,sizeof(server) perror(“connect errorn“); close(sockfd); return -1; while(1) fprintf(stderr,“TCP“); fgets(buffe

8、r,SIZE,stdin); rvalue=write(sockfd,buffer,strlen(buffer),0); if (0=strcmp(buffer,“quitn“)|(0=strcmp(buffer,“QUITN“) fprintf(stderr,“quit.n“); break; if (0rvalue) fprintf(stderr,“error in receiving datan“); continue; sscanf(buffer,“%s“,cmd); if (0=strcmp(“cd“,cmd)|(0=strcmp(“CD“,cmd) continue; len=si

9、zeof(struct sockaddr); rvalue=read(sockfd,buffer,SIZE,0); if (0 #include #include #include #include #include #define PORT 8888 /*server port */ #define SIZE 2048 /* 2K BUFFER */ int exec (char* command,char* result) FILE * in; int len; char c; len=0; bzero(result,sizeof(result); in=popen(command,“r“

10、); if (NULL=in) fprintf(stderr,“error in create a pipen“); return -1; while(c=fgetc(in)!=EOF)&(lenrvalue) fprintf(stderr,“error in receiving datan“); continue; recv_bufrvalue-1=0; if (0=strcmp(recv_buf,“quit“) fprintf(stderr,“the client is quitn“); close(connected); break; sscanf(recv_buf,“%s %s“,cm

11、d,path); if (0=strcmp(“cd“,cmd) |(0=strcmp(“CD“,cmd) chdir(path); continue; fprintf(stderr,“the result is n%s“,send_buf); exec(recv_buf,send_buf); rvalue=-1; rvalue=write(connected,send_buf,strlen(send_buf); if (0rvalue) fprintf(stderr,“error in sending datan“); continue; close(connected); /phrase 4:release the socket close(sockfd); return EXIT_SUCCESS; /* - end of function main - */ 數(shù)據(jù)記錄 和計(jì)算 TCP套接字編程(cont.): 工作原理: 客戶端接收用戶輸入的命令,客戶端通過套接字將命令傳送給服務(wù)器端, 服務(wù)器在收到

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論