Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Client/Server Multicast API

Reply
Thread Tools

Client/Server Multicast API

 
 
nazgulero
Guest
Posts: n/a
 
      05-16-2005
Hello all,


I am fairly new to C, and I am trying to write a client/server API
for multicast. I have come across the script below, but for some
reason, the server does not get any of the multicast traffic from the
client, so I am afraid that somewhere there might be a mistake in the
script. Would anybody care to have a quick check ? Never mind the
French comments, I ŽborrowedŽ the script from a French website...


// Server code
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/socket.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


#define GROUP "239.137.194.111"
#define PORT 55555
#define TAILLE 512


int main()
{
int sockfd;
struct sockaddr_in servaddr;
struct ip_mreq imr;
int len_serv;
char message_recu[TAILLE];


memset(message_recu, 0, TAILLE);


len_serv = sizeof(servaddr);


sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockfd < 0)
{
perror("Problemes lors de l'ouverture de la socket ");
exit(1);



}


memset(&servaddr, 0, len_serv);
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;

if(bind(sockfd, (struct sockaddr *)&servaddr, len_serv) < 0)
{
perror("Problemes lors de l'association de la socket a un port ");
exit(1);



}


inet_aton(GROUP, &(imr.imr_multiaddr));
imr.imr_interface.s_addr = INADDR_ANY;

if(setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(imr))

< 0)
{
perror("Problemes lors de la demande de JOIN ");
exit(1);



}


if(recvfrom(sockfd, message_recu, TAILLE, 0, (struct sockaddr
*)&servaddr, &len_serv) < 0)
{
perror("Problemes lors de la lecture d'une donnee ");
exit(1);

}


printf("%s\n", message_recu);
close(sockfd);


}


// Client Code

#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/socket.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


#define GROUP "239.137.194.111"
#define PORT 55555
#define TAILLE 512


int main()
{
int sockfd;
struct sockaddr_in servaddr;
char message[TAILLE];


memset(message, 0, TAILLE);
sprintf(message, "Coucou");


sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockfd < 0)
{
perror("Problemes lors de l'ouverture de la socket ");
exit(1);



}


memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
inet_aton(GROUP, &(servaddr.sin_addr));

if(sendto(sockfd, message, strlen(message), 0, (struct sockaddr
*)&servaddr, sizeof(servaddr)) < 0)
{
perror("Problemes lors de l'envoi du message ");
exit(1);



}
}


Your help is greatly appreciated.

Regards,


GP

 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      05-17-2005
On 16 May 2005 03:29:26 -0700, "nazgulero" <>
wrote in comp.lang.c:

> Hello all,
>
>
> I am fairly new to C, and I am trying to write a client/server API
> for multicast. I have come across the script below, but for some
> reason, the server does not get any of the multicast traffic from the
> client, so I am afraid that somewhere there might be a mistake in the
> script. Would anybody care to have a quick check ? Never mind the
> French comments, I ŽborrowedŽ the script from a French website...
>
>
> // Server code
> #include <stdio.h>
> #include <string.h>
> #include <netinet/in.h>
> #include <unistd.h>
> #include <sys/socket.h>
> #include <signal.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>


[snip]

Sorry, wrong newsgroup. Three of the headers above are part of the C
language, the other six are non-standard extensions provided by your
particular compiler/OS combination and off-topic here. Standard C
does not provide any built-in support for any sort of networking.

You need to ask about this in a platform specific group, for your
specific UNIX variant.

Perhaps news:comp.os.linux.development.apps if you use Linux, or
generically news:comp.unix.programmer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net Profiler API in 64 bit windows -FunctionMapper callback API =?Utf-8?B?TGVv?= Windows 64bit 0 09-05-2007 06:10 PM
Profiling API or Membership API John123 ASP .Net 0 10-20-2006 03:18 PM
Client/server Multicast API nazgulero C++ 2 05-16-2005 10:26 AM
Calling the C API from Python and Python program from same C API -bidirectional Praveen, Tayal (IE10) Python 0 03-17-2005 06:33 AM
What API replaces the unlock API that existed in gcc 2.9.3? Shlomo Anglister C++ 1 08-02-2004 06:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57