473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Client/server Multicast API

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...

// Code du serveur
#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);

}
// Code du client

#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

Jul 23 '05 #1
2 4994
nazgulero wrote:
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


First of all, the code you posted is C, not C++ code.
Second, it makes use of -- and totally depends on -- POSIXisms that are
neither part of standard C nor C++.

Please try news:comp.unix.programmer; you're off topic here.

HTH,
--ag

[snip]

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #2
Hello Artie,

I think need to get a hold of the `C++ for Dummies´ book first before
posting...my apologies for the OT, and thanks to pointing me to the
right group...

GP

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas | last post by:
Hi, Sorry for the stupid subject, but here it goes: I need a simple Webserver which can 1. serve xmlrpc-methods 2. send multicast packets on local network to get response from a similar...
1
by: nazgulero | last post by:
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...
7
by: Jim H | last post by:
Is there something special I need to do to send data to a multicast IP and have it go across a router? Router is a Win2000 Server connecting 2 networks via RRAS PPTP. The routing appears to be...
2
by: Terry | last post by:
I've got a strange problem receiving multicast packets in a C# application. What's strange is that it works *sometimes* but not always. I create a socket, call bind(), set the multicast socket...
2
by: chewie | last post by:
I'm in the process of creating a multicast application but I'm having difficulty getting the UDPClient to work. The UDPClient works on my local machine only, not across the network. I've been able...
0
by: ollii | last post by:
Hello evryboody, i created client and srever program that they can both communicate together by TCP and UDP, but when i want to send message to server from client i get error on the server i get...
4
by: skpopu | last post by:
I have a two systems and I am able to communicate both systems using udp server and client at both ends but I need to make one system as concurrent server and now I would like to add one more...
5
by: AliRezaGoogle | last post by:
Hi, I have a conceptual question on Events and Multicast Delegates. Let me explain: As we know an event is a multicast delegate. What we declare as an event is inherently a multicast delegate....
7
by: Anil | last post by:
I have a Javascript program which runs in the browser and has functions work(), and stop(). It listens to commands from the server to work() and can be interrupted by the server to stop(). I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.