| Dear, How can I use rtnet to send or receive packet in c? i am a bit confused because no examples or tutorial to build the program using rtnet while I search it in internet. i want to make a real time packet sending program and a real time packet receiver program using rtnet 0.9.12 and xenomai 2.5.4. the operating system that I use is linux fedora 13 kernel 2.6.32.11. Is it just add some include and some lines from standard udp packet server and client program? thanks a lot ========================== //the standard udp packet server that I build (server.c) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <mqueue.h> #include <fcntl.h> #include <sys/stat.h> #include <pthread.h> #include <sys/mman.h> #include <signal.h> #include <limits.h> #define PORT 7788 #define BUFLEN 65000 #define NPACK 10000000 void diep (char *s) { perror (s); exit (1); } int main (void) { struct sockaddr_in si_me, si_other; int s, i, slen=sizeof(si_other); char buf[BUFLEN]; if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))== -1) { diep("socket"); } memset ((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(s, &si_me, sizeof(si_me)) == -1) { diep("bind"); } for(i = 0; i < NPACK; i++) { if(recvfrom(s, buf, BUFLEN, 0, &si_other, &slen) == -1) { diep("recvfrom()"); } printf("received packet from %s:%d\n Data: %s\n\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf); } close(s); return 0; } ============================= //the standard udp packet client (client.c) #include <stdlib.h> #include <unistd.h> #include <string.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <mqueue.h> #include <fcntl.h> #include <sys/stat.h> #include <pthread.h> #include <sys/mman.h> #include <signal.h> #include <limits.h> #define PORT 7788 #define BUFLEN 65000 #define NPACK 10000000 #define SRV_IP "167.205.34.150" void diep (char *s) { perror (s); exit (1); } int main () { struct sockaddr_in si_other; int s, i, slen=sizeof(si_other); char buf[BUFLEN]; if((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { diep("socket"); } memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family=AF_INET; si_other.sin_port = htons(PORT); if(inet_aton(SRV_IP, &si_other.sin_addr)==0) { fprintf(stderr, "inet_aton () failed\n"); exit (1); } for(i=0; i< NPACK; i++) { printf("sending packet %d\n", i); sprintf(buf, "This is packet %d\n",i); if (sendto(s, buf, BUFLEN, 0, &si_other, slen) == -1) { diep("sendto()"); } } close(s); return 0; } ============================ |