CC3000 Multicast

From Texas Instruments Wiki
Jump to: navigation, search

Description

Multicast is the delivery of a message or information to a group of destinations simultaneously in a single transmission from the source.

CC3000 is capable to transmit and receive multicast packets.

In order to transmit a multicast packet, sendto() should be used with the right multicast IP and port number.

In order to receive a multicast packet bind() should be used in order to bind to the right multicast IP and port number.


Example

Transmit

main(void)
{
 
 sockaddr tSocketAddr;
 char McastPacketTx[] = {'d','a','t','a'};
 
// create MCAST address 224.0.1.187 port 5454
 
 tSocketAddr.sa_family = AF_INET;
 
// Destination port
 tSocketAddr.sa_data[0] = 0x15;
 tSocketAddr.sa_data[1] = 0x4e;
 
// Destination IP address
 tSocketAddr.sa_data[2] = 0xe0;
 tSocketAddr.sa_data[3] = 0;
 tSocketAddr.sa_data[4] = 1;
 tSocketAddr.sa_data[5] = 0xbb;
 
 McastPacketTxLen = 4;
 
 ulTxSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
//Send the multicast packet
 sendto(ulTxSocket, McastPacketTx, McastPacketTxLen, 0, &tSocketAddr, sizeof(sockaddr));
 
}


Receive

main(void)
{
 
 sockaddr tSocketAddr;
 sockaddr from;
 socklen_t fromlen = 8;
 
// create MCAST address 224.0.1.187 port 5454
 
  tSocketAddr.sa_family = AF_INET;
 
// the destination port
  tSocketAddr.sa_data[0] = 0x15;
  tSocketAddr.sa_data[1] = 0x4e;
 
// the destination IP address
  tSocketAddr.sa_data[2] = 0xe0;
  tSocketAddr.sa_data[3] = 0;
  tSocketAddr.sa_data[4] = 1;
  tSocketAddr.sa_data[5] = 0xbb;
 
  ulSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
  bind(ulSocket, &tSocketAddr, sizeof(sockaddr));
 
//Receive the multicast packet
 recvfrom(ulSocket, &McastPacketRx[0], recvDataLen, 0, &from, &fromlen);
 
}