Advertisement
  Home Thursday, 24 July 2008 
Main Menu
 Home
 News
 FAQ
 C Source
 The Web Links
 Contact Us
 Administrator

Login Form
Username

Password

Remember me
Forgotten your password?
No account yet? Create one

Statistics
OS: Windows
PHP: 5.2.7-dev
MySQL: 4.0.15-nt
Time: 10:50
Members: 477
Hits: 493824
News: 11
WebLinks: 4

Online Users
No Users Online

Newsflash
Urgent Cisco messages on virus and security issues that affect networking technologies and protocols http://www.cisco.com/en/US/tech/tk828/tk363/tech_security_advisories_list.html

Multicast Server Example   PDF  Print  E-mail 
Written by Bilbo Baggins  
Tuesday, 29 June 2004
Simple example of a IP Multicast server (with compile instructions and execution intrutions) /* multisnd

/*  multisnd.c - see also diewitherror.c and multirec.c */

/* compile  $ cc -o multisnd.exe multisnd.c diewitherror.c */

/*                   program      multicast ip  port  data          ttl */

/* useage example $ ./multisnd.exe 224.0.22.1 9210 testtesttesttest 2

/* tested with cygwin gcc win32- linux gcc -sun */

 

#include <stdio.h>      /* for fprintf() */

#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */

#include <arpa/inet.h>  /* for sockaddr_in and inet_addr() */

#include <stdlib.h>     /* for atoi() and exit() */

#include <string.h>     /* for memset() */

#include <unistd.h>     /* for sleep() */

 

void DieWithError(char *errorMessage);  /* External error handling function */

 

int main(int argc, char *argv[])

{

    int sock;                         /* Socket */

    struct sockaddr_in multicastAddr; /* Multicast address */

    char *multicastIP;                /* IP Multicast address */

    unsigned short multicastPort;     /* Server port */

    char *sendString;                 /* String to multicast */

    unsigned char multicastTTL;       /* TTL of multicast packets */

    unsigned int sendStringLen;       /* Length of string to multicast */

 

    if ((argc < 4) || (argc > 5))         /* Test for correct number of parameters */

    {

        fprintf(stderr,"Usage:  %s <Multicast Address> <Port> <Send String> [<TTL>]\n",

                 argv[0]);

        exit(1);

    }

 

    multicastIP = argv[1];            /* First arg:  multicast IP address */

    multicastPort = atoi(argv[2]);    /* Second arg:  multicast port */

    sendString = argv[3];             /* Third arg:  String to multicast */

 

    if (argc == 5)                     /* Is TTL specified on command-line? */

        multicastTTL = atoi(argv[4]);  /* Command-line specified TTL */

    else

        multicastTTL = 1;              /* Default TTL = 1 */

 

    /* Create socket for sending/receiving datagrams */

    if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)

        DieWithError("socket() failed");

 

    /* Set TTL of multicast packet */

    if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (void *) &multicastTTL,

          sizeof(multicastTTL)) < 0)

        DieWithError("setsockopt() failed");

 

    /* Construct local address structure */

    memset(&multicastAddr, 0, sizeof(multicastAddr));   /* Zero out structure */

    multicastAddr.sin_family = AF_INET;                 /* Internet address family */

    multicastAddr.sin_addr.s_addr = inet_addr(multicastIP);/* Multicast IP address */

    multicastAddr.sin_port = htons(multicastPort);         /* Multicast port */

 

    sendStringLen = strlen(sendString);  /* Find length of sendString */

    for (;;) /* Run forever */

    {

        /* Multicast sendString in datagram to clients every 3 seconds */

        if (sendto(sock, sendString, sendStringLen, 0, (struct sockaddr *)

              &multicastAddr, sizeof(multicastAddr)) != sendStringLen)

            DieWithError("sendto() sent a different number of bytes than expected");

        sleep(3);

    }

    /* NOT REACHED */

}

 

 

 

 

 

Last Updated ( Tuesday, 29 June 2004 )

Browser Prefs
Add to Favorites
Make Home Page

Newsfeeds
Internet:Business News
Thu, 24 Jul 2008 10:50
Giving its resellers more of the action and room to grow is part of Sun's plan to give its overall business a boost.
Sun Bets on Channel Strategy Revamp
UPDATED: All eyes on the virtualization darling after Diane Greene's recent ouster as CEO.
VMware's Earnings Pop, Outlook Cloudy
Tuesday was a study in contrasts, as the entire chip sector fell 4.5%as the rest of the market gained.
Stocks Rally Despite Tough Tech Earnings
BBC: Technology
Thu, 24 Jul 2008 10:50
BBC News
Six of the UK's biggest net providers sign up to a government plan to tackle illegal file-sharing.
Net firms in music pirates deal
UK academics sign a letter criticising the ongoing neglect of Bletchley Park - home of the wartime codebreakers.
'Neglect' of codebreakers' HQ
A businessman wins £22,000 in libel and breach of privacy after his personal details were printed on the Facebook website.
Payout for false Facebook profile

Most Read
Multicast Client Example
Multicast Server Example
Welcome to IP Multicast Standards Initiative
diewitherror.c Multicast Client & Server
What ipmulticast.com will provide

: Home :: News :: FAQ :: C Source :: The Web Links :: Contact Us :: Administrator :
powered by world multicast ietf rmt wg ietf rmt wg