arm_linux與windows 利用RTP協議進行多播通訊

來源:互聯網
上載者:User

作為多播資料的發送端,arm_linux端加入多播組不是必須的,可以加入,也可以不加入。

arm_linux端資料發送程式:(只給出功能函數)

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 to * 
 * 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;
}

windows端接收資料程式,需要加入多播組:

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("多播地址無效");
  return -1;
 }
 destip  = ntohl(destip);
 status  = sess.Create(portbase);
 dlg->checkerror(status);
 iscast = sess.SupportsMulticasting();
 if(!iscast)
 {
  sess.Destroy();
  AfxMessageBox("不支援多播");
  return -1;
 }
 if(sess.JoinMulticastGroup(destip) < 0)
 {
  AfxMessageBox("加入多播組失敗");
  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("收到資料");
   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("會話結束 /n");
 dlg->m_brtprunning = FALSE;
 return 0;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.