Arm_linux and Windows use RTP protocol for Multicast Communication

Source: Internet
Author: User

As the sender of multicast data, adding arm_linux to multicast groups is not required. You can add or not.

Arm_linux data sending program: (only functional functions are provided)

Void multicast_thread ()
{
Rtpsession sess;
Int portbase = 6000;
Int status;
// Int length;
Int loop;
Bool iscast;
Unsigned long destip;
Unsigned long localip;
Char * buff = "multicasting test ";
Int length = strlen (buff );
Destip = inet_addr ("233.0.0.1 ");
Localip = inet_addr ("172.29.26.101 ");
If (destip = inaddr_none | localip = inaddr_none)
{
Printf ("Bad IP address specfied/N ");
Return;
}
Destip = ntohl (destip );
Localip = ntohl (localip );
Status = sess. Create (portbase, localip );
Checkerror (Status );
Iscast = sess. supportsmulticasting ();
If (! Iscast)
{
Sess. Destroy ();
Printf ("the RTP Library was not complied with multicasting support/N ");
Return;
}
/*************************************** **********************
* As a sender to a multicastgroup, it doesn' t have to add *
* The group. Both can send the data successfully .*
**************************************** **********************/
// Sess. joinmulticastgroup (destip );
Status = sess. adddestination (destip, portbase );
Checkerror (Status );
For (loop = 0; loop <1000; loop ++)
{
Status = sess. sendpacket (buff, length, 1, false, 25 );
Printf ("Send packet: % d/N", loop + 1 );
Sleep (1 );
}
Sess. cleardestinations ();
// Sess. leavemulticastgroup (destip );
Sess. Destroy ();
Return;
}

To receive data programs on Windows, you must add them to multicast groups:

Uint multicast_thread (lpvoid)
{
Cadmintooldlg * DLG = (cadmintooldlg *) afxgetapp ()-> getmainwnd ();
Rtpsession sess;
Int portbase, status, length;
Unsigned long destip;
Unsigned char * rawdata;
Bool iscast;
// Cstring STR;
Portbase = 6000;
Destip = inet_addr (Multicast );
If (destip = inaddr_none)
{
Afxmessagebox ("invalid multicast address ");
Return-1;
}
Destip = ntohl (destip );
Status = sess. Create (portbase );
DLG-> checkerror (Status );
Iscast = sess. supportsmulticasting ();
If (! Iscast)
{
Sess. Destroy ();
Afxmessagebox ("multicasting is not supported ");
Return-1;
}
If (sess. joinmulticastgroup (destip) <0)
{
Afxmessagebox ("failed to join multicast group ");
Return-1;
}
// Sess. setreceivemode (receivemode_acceptsome );
// Sess. addtoacceptlist (destip, 1, portbase );
DLG-> recvbytes = 0;
DLG-> COUNT = 0;
While (1)
{
Sess. polldata ();
If (sess. gotofirstsourcewithdata ())
{
// Afxmessagebox ("receive data ");
Rtppacket * pack;
While (pack = sess. getnextpacket ())! = NULL)
{
Length = pack-> getpayloadlength ();
Rawdata = pack-> getpayload ();
For (INT I = 0; I <length; I ++)
{
DLG-> data [DLG-> recvbytes] = rawdata [I];
DLG-> recvbytes ++;
}
DLG-> count ++;
}
}
If (DLG-> exitflag = 1 | purview = 0)
{
DLG-> m_brtprunning = false;
Sess. Destroy ();
Exitthread (-1 );

}
}
Sess. leavemulticastgroup (destip );
Sess. Destroy ();
Afxmessagebox ("session end/N ");
DLG-> m_brtprunning = false;
Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.