From: Ramon Rusli <mon_nie@domain.hid>
To: xenomai@xenomai.org
Cc: Ramon Rusli <mon_nie@domain.hid>
Subject: [Xenomai-help] [ask] how to send and receive packet in real time network with xenomai n rtnet
Date: Mon, 21 Feb 2011 15:52:09 +0800 (SGT) [thread overview]
Message-ID: <602976.88951.qm@domain.hid> (raw)
[-- Attachment #1: Type: text/plain, Size: 3305 bytes --]
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;
}
============================
[-- Attachment #2: Type: text/html, Size: 5006 bytes --]
next reply other threads:[~2011-02-21 7:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-21 7:52 Ramon Rusli [this message]
2011-02-21 11:13 ` [Xenomai-help] [ask] how to send and receive packet in real time network with xenomai n rtnet Gilles Chanteperdrix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=602976.88951.qm@domain.hid \
--to=mon_nie@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.