S3C44B0X在嵌入式Socket通信系統(tǒng)中的應(yīng)用
if ((s = socket(AF_
INET,SOCK_STREAM,0)) 0){
perror ("socket");
exit (1);
}
bzero (addr,sizeof (addr));
addr.sin_family = AF_INET;
addr.sin_port=htons((unsigned short)atoi(argv[2]));
hp = gethostbyname(argv[1]);
memcpy(local_addr.sin_addr.s_addr,hp->h addr,4);
in.s_addr = local_addr.sin_addr.s_addr;
printf ("Domain Name %sn" argv
printf ("IP address :%sn",inet_ntoa (in));
printf("%s,%sn",hp->h_name,argv[2]);
addr.sin_addr.s_addr=inet_addr(hp->h_name);
if connect(s,(struct sockaddr *)addr,sizeof (addr))0){
perror ("connect");
exit (1);
}
recv (s,buffer,sizeof (buffer),0);
printf ("%sn",buffer);
while(1);
bzero(buffer,sizeof (buffer));
read (STDIN_FILENO,buffer,sizeof(buffer));
if (send (s,buffer,sizeof (buffer),0)0){
perror ("send");
exit (1);
}
}
}
4 結(jié)束語
設(shè)計開發(fā)了基于S3C44B0X的以太網(wǎng)通信系統(tǒng),并利用uClinux操作系統(tǒng)強(qiáng)大的網(wǎng)絡(luò)功能實現(xiàn)了Socket通信?由于uClinux目前只支持flat格式的可執(zhí)行文件,因此本設(shè)計是在先建立好uClinux開發(fā)環(huán)境的情況下,把用戶自行開發(fā)的應(yīng)用程序通過宿主PC機(jī)上的交叉編譯器轉(zhuǎn)化為flat格式,然后再通過FTP添加到目標(biāo)硬件開發(fā)平臺上運(yùn)行的?文中的客戶端應(yīng)用程序已經(jīng)在基于ARM7TDMI核的S3C44B0X處理器的嵌入式開發(fā)平臺上成功運(yùn)行,并成功地和宿主PC機(jī)的服務(wù)器端應(yīng)用程序?qū)崿F(xiàn)了Socket通信?當(dāng)然,也可以把目標(biāo)硬件開發(fā)平臺當(dāng)作服務(wù)器端,而把宿主PC機(jī)當(dāng)作客戶端來進(jìn)行雙向文件傳輸?
評論