Advertisement
  Home Saturday, 31 July 2010 
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: 23:16
Members: 1126
Hits: 844054
News: 13
WebLinks: 6

Online Users
No Users Online

Newsflash
The Triple Play Forum, the European Advanced Networking Test Center (EANTC) and Upper Side will organize a multi-vendor public interoperability showcase in the area of Triple Play services during the TVoDSL Conference, to be held January 25-28 2005, with a private hot-staging test event in Berlin, Germany two weeks before.
The interoperability test and demonstration addresses IP multicast and QoS transport: DSLAMs , DSL modems , FTTX CPE   switches and Ethernet Switches


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
Sat, 31 Jul 2010 22:47
With Apple and Google bearing down, the early mover in enterprise smartphones has its quarterly numbers fall short.
RIM Earnings Show Heat From iPhone, Android
The technology world's most quotable quips and comments from around the Web.
Say What? The Week's Top Five IT Quotes
The software and server giant posted a profit of $3 billion for the latest quarter.
Oracle Rides Sun to Big 4Q Earnings
BBC: Technology
Sat, 31 Jul 2010 23:02
Owners of mobile phones are being asked to test the security of their network to see if enough is being done to stop eavesdropping.
Call to check on mobile security
Twitter, the social networking site which allows users to say something in up to 140 characters, sees its 20 billionth message sent.
Twitter passes 20 billionth tweet
Newsbeat's had an exclusive look at new training being given to UK soldiers at the Royal School of Artillery in Wiltshire.
UK troops use iPad app for fire mission training

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