473,624 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.11 1"
#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("Problem es lors de l'ouverture de la socket ");
exit(1);
}

memset(&servadd r, 0, len_serv);
servaddr.sin_fa mily = AF_INET;
servaddr.sin_po rt = htons(PORT);
servaddr.sin_ad dr.s_addr = INADDR_ANY;

if(bind(sockfd, (struct sockaddr *)&servaddr, len_serv) < 0)
{
perror("Problem es lors de l'association de la socket a un port ");
exit(1);
}
inet_aton(GROUP , &(imr.imr_multi addr));
imr.imr_interfa ce.s_addr = INADDR_ANY;

if(setsockopt(s ockfd, IPPROTO_IP, IP_ADD_MEMBERSH IP, &imr, sizeof(imr))
< 0)
{
perror("Problem es lors de la demande de JOIN ");
exit(1);
}

if(recvfrom(soc kfd, message_recu, TAILLE, 0, (struct sockaddr
*)&servaddr, &len_serv) < 0)
{
perror("Problem es 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.11 1"
#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("Problem es lors de l'ouverture de la socket ");
exit(1);
}

memset(&servadd r, 0, sizeof(servaddr ));
servaddr.sin_fa mily = AF_INET;
servaddr.sin_po rt = htons(PORT);
inet_aton(GROUP , &(servaddr.sin_ addr));

if(sendto(sockf d, message, strlen(message) , 0, (struct sockaddr
*)&servaddr, sizeof(servaddr )) < 0)
{
perror("Problem es lors de l'envoi du message ");
exit(1);
}

}

Your help is greatly appreciated.

Regards,

GP

Jul 23 '05 #1
2 5016
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
2062
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 server acting as master on the given network 3. somehow serve a single file using simple http/webserver methods to
1
4303
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 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...
7
7703
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 working because I can ping the multicast address and get responses from the server on the other network. I didn't think ping would work like that but as long as I have the server process running I can ping the multicast IP and get a response. The...
2
3117
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 option and then fire off a thread that calls "receiveFrom()" in a loop. This works sometimes, but other times it'll get into a funk where the "receiveFrom()" call doesn't return even though a packet trace capture (Ethereal) shows that the...
2
7261
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 to get the multicast message to work across a network by creating a socket, but I can't get it to work via UDPClient. What is the difference between the two? Why does the socket method work and not the UDPClient? Thanks ...
0
1803
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 error "Segmentation Fault" This is Code for server: /* server_it.c: DST iterative echo server to be linked with DST_sock */ #include <stdio.h>
4
5995
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 system into the group and now I would like to multicast the message from My main server to the new joined system and now I should be able to send and recieve from both the other systems to the main server. Exactly what I have with me is : Two systems...
5
8909
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. I really do not undrestand what additional features the "event" keyword adds to multicast delegate. The only thing that I see as an additional feature is a "Thunder Icon" near event name in VS IDE when intellisense works;).
7
4684
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 using XmlHttpRequest to talk to the server. So I use http GET to send a command "ready" to the server, which replies at some point in time by sending "work" which is invoked by the callback. As per my understanding, the browser client is single...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.