multicast application.....???
Results 1 to 3 of 3

Thread: multicast application.....???

  1. #1
    Junior Member
    Join Date
    May 2005
    Posts
    8

    Unhappy multicast application.....???

    hi all....

    i m assigned this job to test my network which comprises of 8 routers for multicasting (pim,dvmrp etc) but for this i need a multicast application(obviously..) can anybody tell me where i can get a good one (client and server) which works accross different networks???

    thanx

  2. #2
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    udpcast worked for me about two years ago. I used it in a netboot/backup-situation where the used ramdisk (for booting) was under four mb's. You'll find more information at http://udpcast.linux.lu/
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  3. #3
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Actually, I was a little motivated to write a little multicast client-server application
    myself. The server sends a string once a second (XSleep[1]) to a multicast address.
    I've set the TTL to 3 to enable small hops, if the routers support multicasting.
    The clients join the multicast group to receive the string. The code does work
    as well under Windows as Linux - just a few lines (headers) have to be modified.

    This is for educational purposes only I tried to be as close to the "common
    notation" as possible to simplify comparison with other source codes out there.

    The server:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock.h>
    
    #include "XSleep.h"
    
    int main(){
    	WSADATA wsda;				
    	WSAStartup(0x0101,&wsda);	// winsock version number
    
    	int sockfd;
    	struct sockaddr_in multicast_sockaddr;
    	
    	char multicast_ip[16] = "224.000.111.222";
    	unsigned short multicast_port = 12345;
    	unsigned char multicast_ttl = 3;
    
    	char probe[17] = "Hello World! 000";
    	unsigned int probe_length = strlen(probe);
    	int counter=0;
    
    // get a socket file descriptor and set the socket option to multicast
    	sockfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    	setsockopt(sockfd,IPPROTO_IP,IP_MULTICAST_TTL, (const char *)&multicast_ttl, sizeof(multicast_ttl));
    
    // initialise the multicast sockaddr
    	memset(&multicast_sockaddr,0,sizeof(multicast_sockaddr));
    	multicast_sockaddr.sin_family = AF_INET;
    	multicast_sockaddr.sin_addr.s_addr = inet_addr(multicast_ip);
    	multicast_sockaddr.sin_port = htons(multicast_port);
    
    // start the server
    	while(1){
    		sprintf(probe,"Hello World! %.3d",counter%1000);
    
    		if ((unsigned)sendto(sockfd,probe,probe_length,0,
    			(struct sockaddr *) &multicast_sockaddr,sizeof(multicast_sockaddr))!=probe_length){
    				printf("sendto failed. Aborting server.");
    				exit(1);
    		} else  printf("Sending: \"%s\"\n",probe);
    		
    		XSleep(1000);
    		counter++;
    	
    	}
    
    	WSACleanup();
    	closesocket(sockfd); 
    
    	return 0;
    }

    The client:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock.h>
    
    int main(){
    	WSADATA wsda;				
    	WSAStartup(0x0101,&wsda);	// winsock version number
    
    	int sockfd;
    	struct sockaddr_in multicast_sockaddr;
    	
    	char multicast_ip[16] = "224.000.111.222";
    	unsigned short multicast_port = 12345;
    	struct ip_mreq multicast_request;
    
    	char probe[17];
    	unsigned int probe_length;
    
    // get a socket file descriptor
    	sockfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    
    // initialise the multicast sockaddr
    	memset(&multicast_sockaddr,0,sizeof(multicast_sockaddr));
    	multicast_sockaddr.sin_family = AF_INET;
    	multicast_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    	multicast_sockaddr.sin_port = htons(multicast_port);
    
    // bind to the port
    	bind(sockfd,(struct sockaddr *) &multicast_sockaddr,sizeof(multicast_sockaddr));
    
    // specify and join the multicast group and accept any interface	
    	multicast_request.imr_multiaddr.s_addr=inet_addr(multicast_ip);
    	multicast_request.imr_interface.s_addr=htonl(INADDR_ANY);
    	setsockopt(sockfd, IPPROTO_IP,IP_ADD_MEMBERSHIP,(const char *) &multicast_request, sizeof(multicast_request));
    
    	while(1){
    		probe_length=recvfrom(sockfd,probe,17,0,NULL,0);
    		if ( probe_length < 0){
    					printf("recvfrom failed. Aborting client.");
    					exit(1);
    		} else{
    				probe[16]=0;
    				printf("Received: \"%s\"\n",probe);
    		}
    	}
    
    	WSACleanup();
    	closesocket(sockfd); 
    
    	return 0;
    }
    Do not forget to link the library WSock32.lib. If you want to read
    more about multicasting, there is a pretty good introduction[2]
    available. I would suggest to play with different settings (pim,...),
    in particular with heavy load traffic. (Guus' link).

    Cheers

    [1] http://www.codeguru.com/Cpp/misc/misc/article.php/c211/
    [2] http://userpage.fu-berlin.de/~tangua...ticast_rou.htm
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •