ʵÏÖ˼·£º±¾³ÌÐòÊÇͨ¹ýUDPÐÒéÀ´·¢ËÍÏûÏ¢£¬ÏûÏ¢µÄÄÚÈÝÒÔ¼°´«µÝµÄµØÖ·ÊÇÓÉmainº¯ÊýµÄ²ÎÊýÀ´´«µÝ¸ø½ø³ÌµÄ¡£²ÎÊýʾÀýÈ磺 AB5hello
ÿÌõÏûÏ¢µÄ³¤¶ÌΪ8×Ö½Ú
ÏûÏ¢µÄ½á¹¹ÈçÏ£º
typedef struct
{
char self_module_id;//×Ô¼ºµÄID£¬¸øÿÌõÏûÏ¢ÌùÉÏ×Ô¼ºµÄ±ê¼Ç£¬Ê¹½ÓÊÕ·½ÖªµÀÊÇË·¢Ë͹ýÀ´µÄ
char dst_module_id;//Ä¿µÄID£¬¾ö¶¨Ã¿ÌõÏûÏ¢·¢Ë͵ÄÄ¿µÄ£¬Í¨¹ý´ËID¾ö¶¨Ä¿µÄ·¾¶
int length;//ÏûÏ¢³¤¶Ì
char msg[5];//ÏûÏ¢ÄÚÈÝ
}msg_struct;
·¢ËÍʵÏÖ¹ý³Ì£º1 ͨ¹ý¶ÔÏûÏ¢×ܳ¤¶È£¨¼´mainº¯Êý²ÎÊý×ܳ¤¶È£©³ý8£¬ÅжÏÓжàÉÙÌõÍêÕûµÄÏûÏ¢
2 ͨ¹ýµ÷ÓÃÒ»´Îsendtoº¯Êý¾Í·¢ËÍÒ»ÌõÏûÏ¢£¬¸ù¾ÝÊý¾Ý½á¹¹È¡µÃÏàÓ¦µÄÄ¿µÄµØÖ·À´¾ö¶¨·¢Ë͵Ä·¾¶£¬Ò²¾ÍÊÇÿ8¸ö×Ö½Ú¾ÍÅжÏÒ»´Î£¬ÏûÏ¢ÊÇ·¢¸øÄĸöÄ¿µÄµØÖ·µÄ¡£Ö±µ½·¢ÍêËùÓеÄÍêÕûµÄÏûÏ¢¡£
3 ×îºóÒ»ÌõÏûÏ¢»òÐíÊDz»Âú8¸ö×ֽڵģ¬Í¨¹ý¶ÔÏûÏ¢×ܳ¤¶ÈÈ¡Ä££¬»ñµÃµ½Õâ¸ö²»ÍêÕûÏûÏ¢µÄ³¤¶È£¬²¢·¢ËÍÕâÌõÏûÏ¢¡£
¶ÁȡʵÏÖ¹ý³Ì£º1 ͨ¹ýrecvfrom»ñµÃÈ«²¿µÄÔÚÃèÊö·ûÉϵÄÏûÏ¢£¬²¢½«Æä´æÈ뻺³åÇørch
2 ¿ªÊ¼´¦Àí´æÈërchµÄÏûÏ¢£¬Í¨¹ý·Ö°ü»úÖÆ£¬°ÑËüÖØдò°ü³ÉÔ¤Ïȶ¨ÒåµÄÏûÏ¢½á¹¹Ìå
3 Ïȱ£´æÍêÕûµÄÏûÏ¢£¬ÔÙ±£´æ²»ÍêÕûµÄÏûÏ¢¡£
³ÌÐò´úÂëÈçÏÂ
/*-------------------------------------------------------------------------
This is a client program
-------------------------------------------------------------------------*/
#include
#include
#include
#include
#include
#include
#include
#include
#define SIZE 32
#define MAXTEXT 256
int main(int argc,char **argv)
{
int src_sockfd;
int dst_sockfd;
int self_sockfd;
int n_read,n_write,len,rcd,i,o,k;
struct sockaddr_un src_sockaddr,dst_sockaddr,self_sockaddr;
//int result;
//char argv[1][MAXTEXT];
char rch[MAXTEXT];
//char dst_module_id;
char src_module_id;
//char self_module_id='A';
fd_set read_fd_set,write_fd_set ;
fd_set watchset ;
int maxfd;
typedef struct
{
char self_module_id;
char dst_module_id;
int length;
char msg[5];
}msg_struct;
msg_struct dst_msg;
dst_msg.self_module_id='A';
msg_struct src_msg;
char *ptr_rch,*ptr_sch;
msg_struct *ptr_rmsg,*ptr_smsg;
ptr_rmsg=&src_msg;
ptr_rch=rch;
ptr_smsg=&dst_msg;
ptr_sch=argv[1];
len=sizeof(src_sockaddr);
if(argc<2)
{
printf(" Aerror1 happen\n");
exit(1);
}
unlink("/home/wewe/code/temp/A");
self_sockfd=socket(AF_LOCAL,SOCK_DGRAM,0);
if(src_sockfd <0)
{
printf("sokcet err, %s \n", strerror(errno));
return -1;
}
bzero(&self_sockaddr,sizeof(self_sockaddr));
self_sockaddr.sun_family=AF_LOCAL;
strcpy(self_sockaddr.sun_path,"/home/wewe/code/temp/A");
bind(self_sockfd,(struct sockaddr*)&self_sockaddr,sizeof(self_sockaddr));
while(1)
//while(1)
{
FD_ZERO( &write_fd_set) ;//Çå³ýwatchset½á¹¹Ìå
FD_SET( self_sockfd, &write_fd_set) ;//½«sever_sockfd¼ÓÈëµ½watchsetÖÐ?
FD_ZERO(&read_fd_set);
FD_SET(self_sockfd,&read_fd_set);
maxfd=self_sockfd;
if(rcd = select( maxfd+1, &read_fd_set,&write_fd_set, NULL, (struct timeval *)0 )>0)
{
if (FD_ISSET( self_sockfd, &read_fd_set ))
{
printf("nengduA\n");
bzero(&src_sockaddr,len);
src_sockaddr.sun_family=AF_LOCAL;
//recvfrom(self_sockfd,&src_module_id,1,0,(struct sockaddr*)&src_sockaddr,&len);
n_read=recvfrom(self_sockfd,rch,10,0,(struct sockaddr*)&src_sockaddr,&len);
rch[n_read]=0;
for(i=0;i
ptr_rmsg->self_module_id=rch[8*i+0];
ptr_rmsg->dst_module_id=rch[8*i+1];
ptr_rmsg->length=rch[8*i+2];
ptr_rmsg->msg[0]=rch[8*i+3];
ptr_rmsg->msg[1]=rch[8*i+4];
ptr_rmsg->msg[2]=rch[8*i+5];
ptr_rmsg->msg[3]=rch[8*i+6];
ptr_rmsg->msg[4]=rch[8*i+7];
printf("ClientA::char from Client %c =%c%c%c%c%c\n",ptr_rmsg->self_module_id,ptr_rmsg->msg[0],ptr_rmsg->msg[1],ptr_rmsg->msg[2],ptr_rmsg->msg[3],ptr_rmsg->msg[4]);
}
o=n_read%8;
if(o==4)
{
ptr_rmsg->self_module_id=rch[8*i+0];
ptr_rmsg->dst_module_id=rch[8*i+1];
ptr_rmsg->length=rch[8*i+2];
ptr_rmsg->msg[0]=rch[8*i+3];
printf("ClientA::char from Client %c =%c\n",ptr_rmsg->self_module_id,ptr_rmsg->msg[0]);
}
else if(o==5)
{
ptr_rmsg->self_module_id=rch[8*i+0];
ptr_rmsg->dst_module_id=rch[8*i+1];
ptr_rmsg->length=rch[8*i+2];
ptr_rmsg->msg[0]=rch[8*i+3];
ptr_rmsg->msg[1]=rch[8*i+4];
printf("ClientA::char from Client %c =%c%c\n",ptr_rmsg->self_module_id,ptr_rmsg->msg[0],ptr_rmsg->msg[1]);
}
else if(o==6)
{
ptr_rmsg->self_module_id=rch[8*i+0];
ptr_rmsg->dst_module_id=rch[8*i+1];
ptr_rmsg->length=rch[8*i+2];
ptr_rmsg->msg[0]=rch[8*i+3];
ptr_rmsg->msg[1]=rch[8*i+4];
ptr_rmsg->msg[2]=rch[8*i+5];
printf("ClientA::char from Client %c =%c%c%c\n",ptr_rmsg->self_module_id,ptr_rmsg->msg[0],ptr_rmsg->msg[1],ptr_rmsg->msg[2]);
}
else if(o==7)
{
ptr_rmsg->self_module_id=rch[8*i+0];
ptr_rmsg->dst_module_id=rch[8*i+1];
ptr_rmsg->length=rch[8*i+2];
ptr_rmsg->msg[0]=rch[8*i+3];
ptr_rmsg->msg[1]=rch[8*i+4];
ptr_rmsg->msg[2]=rch[8*i+5];
ptr_rmsg->msg[3]=rch[8*i+6];
printf("ClientA::char from Client %c =%c%c%c%c\n",ptr_rmsg->self_module_id,ptr_rmsg->msg[0],ptr_rmsg->msg[1],ptr_rmsg->msg[2],ptr_rmsg->msg[3]);
}
else
printf("recevie nothing\n");
sleep(3);
//printf("nengdu2\r\n");
}
if ( FD_ISSET( self_sockfd, &write_fd_set ) )
{ printf("nengxieA\n");
bzero(&dst_sockaddr,len);
dst_sockaddr.sun_family=AF_LOCAL;
n_write=strlen(argv[1]);
for(k=0;k
ptr_smsg->self_module_id=argv[1][8*k+0];
ptr_smsg->dst_module_id=argv[1][8*k+1];
ptr_smsg->length=argv[1][8*k+2];
ptr_smsg->msg[0]=argv[1][8*k+3];
ptr_smsg->msg[1]=argv[1][8*k+4];
ptr_smsg->msg[2]=argv[1][8*k+5];
ptr_smsg->msg[3]=argv[1][8*k+6];
ptr_smsg->msg[4]=argv[1][8*k+7];
if(ptr_smsg->dst_module_id=='B')
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/B");
else
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/C");
sendto(self_sockfd,ptr_smsg,8,0,(struct sockaddr*)&dst_sockaddr,len);
printf("ClientA:: char to Client %c=%c%c%c%c%c\n",ptr_smsg->dst_module_id,argv[1][8*k+3],argv[1][8*k+4],argv[1][8*k+5],argv[1][8*k+6],argv[1][8*k+7]);
}
o=n_write%8;//ÅжÏ×îºÃÒ»Ìõ²»ÍêÕûÏûÏ¢ÓжàÉÙ×Ö½Ú
if(o==4)
{
ptr_smsg->self_module_id=argv[1][8*k+0];
ptr_smsg->dst_module_id=argv[1][8*k+1];
ptr_smsg->length=argv[1][8*k+2];
ptr_smsg->msg[0]=argv[1][8*k+3];
ptr_smsg->msg[1]='0';
ptr_smsg->msg[2]='0';
ptr_smsg->msg[3]='0';
ptr_smsg->msg[4]='0';
if(ptr_smsg->dst_module_id=='B')
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/B");
else
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/C");
sendto(self_sockfd,ptr_smsg,4,0,(struct sockaddr*)&dst_sockaddr,len);
printf("ClientA:: char to Client %c=%c\n",ptr_smsg->dst_module_id,argv[1][8*k+3]);
}
else if(o==5)
{
ptr_smsg->self_module_id=argv[1][8*k+0];
ptr_smsg->dst_module_id=argv[1][8*k+1];
ptr_smsg->length=argv[1][8*k+2];
ptr_smsg->msg[0]=argv[1][8*k+3];
ptr_smsg->msg[1]=argv[1][8*k+4];
ptr_smsg->msg[2]='0';
ptr_smsg->msg[3]='0';
ptr_smsg->msg[4]='0';
if(ptr_smsg->dst_module_id=='B')
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/B");
else
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/C");
sendto(self_sockfd,ptr_smsg,5,0,(struct sockaddr*)&dst_sockaddr,len);
printf("ClientA:: char to Client %c=%c%c\n",ptr_smsg->dst_module_id,argv[1][8*k+3],argv[1][8*k+4]);
}
else if(o==6)
{
ptr_smsg->self_module_id=argv[1][8*k+0];
ptr_smsg->dst_module_id=argv[1][8*k+1];
ptr_smsg->length=argv[1][8*k+2];
ptr_smsg->msg[0]=argv[1][8*k+3];
ptr_smsg->msg[1]=argv[1][8*k+4];
ptr_smsg->msg[2]=argv[1][8*k+5];
ptr_smsg->msg[3]='0';
ptr_smsg->msg[4]='0';
if(ptr_smsg->dst_module_id=='B')
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/B");
else
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/C");
sendto(self_sockfd,ptr_smsg,6,0,(struct sockaddr*)&dst_sockaddr,len);
printf("ClientA:: char to Client %c=%c%c%c\n",ptr_smsg->dst_module_id,argv[1][8*k+3],argv[1][8*k+4],argv[1][8*k+5]);
}
else if(o==7)
{
ptr_smsg->self_module_id=argv[1][8*k+0];
ptr_smsg->dst_module_id=argv[1][8*k+1];
ptr_smsg->length=argv[1][8*k+2];
ptr_smsg->msg[0]=argv[1][8*k+3];
ptr_smsg->msg[1]=argv[1][8*k+4];
ptr_smsg->msg[2]=argv[1][8*k+5];
ptr_smsg->msg[3]=argv[1][8*k+6];
ptr_smsg->msg[4]='0';
if(ptr_smsg->dst_module_id=='B')
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/B");
else
strcpy(dst_sockaddr.sun_path,"/home/wewe/code/temp/C");
sendto(self_sockfd,ptr_smsg,7,0,(struct sockaddr*)&dst_sockaddr,len);
printf("ClientA:: char to Client %c=%c%c%c%c\n",ptr_smsg->dst_module_id,argv[1][8*k+3],argv[1][8*k+4],argv[1][8*k+5],argv[1][8*k+6]);
}
else
printf("send nothing\n");
sleep(3);
//printf("nengxie\r\n");
}
}
//continue;
}
}
82.239.24.* ÓÚ 2007-06-11 08:15:28·¢±í:
05c651254ad0ae257c1cebc20e2a9775 http://hotel-duca-degli-abruzzi-roccaraso.hhknox.net.in/ http://corso-lingua-bambino-online-free.oaxzml.net.in/ http://lista-assegno-componente-nucleo-familiare.dtifhu.net.in/ http://documento-programmatico-sicurezza-dati-personali.ooqqld.net.in/ http://milano-mac-duff-s-pub.ooqqld.net.in/ http://hotel-di-gaiole-in-chianti.hhknox.net.in/ http://fra-andrea-pavia-cappuccino-angola.dtifhu.net.in/ http://psicologia-personalita-bambino-sviluppo-religiosita.dtifhu.net.in/ http://magna-grecia-ristorante-sellia-marina.oaxzml.net.in/ http://materiale-didattico-inglese-scuola-primaria.innltr.net.in/ 319dbbb4ab069a1bfb4a4d4d12c61dcd
201.213.68.* ÓÚ 2007-06-09 07:32:28·¢±í:
086d41a9e7212ddfe86e9dcae4f2a77c http://software-freeware-crea-album-fotografico.akermn.org/ http://art-19-legge-413-91.pauhzy.org/ http://generatore-eolico-ad-asse-verticale.iumzde.org/ http://trucco-splinter-cell-chaos-theory-ps2.akermn.org/ http://agriturismo-nella-liguria-di-ponente.mbxbva.org/ http://agenzia-viaggio-centro-servizio-turistico-treviso.hwqegr.org/ http://dischi-piu-venduti-della-storia.lbpwqo.org/ http://locali-scambista-provincia-di-roma.iumzde.org/ http://produttore-generatore-aria-calda-provincia-milano.pauhzy.org/ http://i-cartoni-dello-zecchino-d-oro.akermn.org/ e44c2d91c99facb894d3b26e91151560
66.130.118.* ÓÚ 2007-06-08 10:01:29·¢±í:
d8191de09d593023fcdbd9849b3af042 http://giacomo-lentini-non-mai-veduto-foco.whguhs.org/ http://carte-da-gioco-forza-italia.ouwnql.org/ http://centro-commerciale-marco-polo-lissone.bzeitz.org/ http://albergo-per-meeting-e-conventions-messina.zouvtz.org/ http://scommessa-serie-b-22-dicembre.rpddkk.org/ http://scaricare-gioco-the-sims-2-gratis.yixkrt.org/ http://google-it-spettacolo-fine-anno-roma.zouvtz.org/ http://modulistica-contratto-collaborazione-co-co.ulhxdx.org/ http://crociera-bordo-adventure-of-the-seas.incgek.org/ http://b-w-cassa-incasso-cwm-cinema.fjhozm.org/ 2e2f8656ca7971267ae7180fc612fe21
201.208.69.* ÓÚ 2007-05-23 23:15:28·¢±í:
http://9301062ed9f5bef5830c8966bbeb04f7-t.mjkson.info 9301062ed9f5bef5830c8966bbeb04f7 http://9301062ed9f5bef5830c8966bbeb04f7-b1.mjkson.info 9301062ed9f5bef5830c8966bbeb04f7 http://9301062ed9f5bef5830c8966bbeb04f7-b3.mjkson.info f6b3bcdaf332fc7274234d3d09378d12
tiantianxian ÓÚ 2007-04-26 15:58:20·¢±í:
ȷʵÊÇÕâ¸öµØ·½ ÊèºöÁË Ð»Ð»°¡
202.165.216.* ÓÚ 2007-04-26 14:32:20·¢±í:
³¤¶ÈÔõô»áÊÇ8¸ö×Ö½ÚÄØ£¿Ä㶨ÒåµÄ½á¹¹Ã÷Ã÷ÊÇ9¸ö×Ö½Ú³¤Ñ½¡£