void CSenderDlg::OnSend() 
{
	CFileDialog  dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
			"(*.*)|*.*|", NULL);
	if (dlg.DoModal() == IDOK)
	{
		m_SourceFile = dlg.GetPathName();	
	}
	source=fopen(m_SourceFile,"rb");
	if ( source == NULL )
	{
		AfxMessageBox("can't access the file");
	}
//#ifdef win32
 	
//#endif	
	size_t bufRead  = 0;
	Mark=true;
	BYTE buffer[bufsize];
	int t;
	
	
	t=sess.Create(5800);
	if(t!=0)AfxMessageBox("can't create");
	if(t==0){sen=true;}
	sess.SetMulticastTTL(1);	//設定multicast封包TTL
	sess.AddDestination(ntohl(inet_addr("127.0.0.1")),6900);	//指定傳送目的端
	//sess.AddDestination(ntohl(inet_addr("192.168.25.79")),6900);
	if(t!=0)AfxMessageBox("can't add destination");
	(void) fseek( source, 0, SEEK_SET );
		while(!feof(source))
		{
			bufRead = fread(buffer, sizeof(BYTE), bufsize, source ); 
			nPT=rand()%64+1;		
			nTSTAMP=rand()%1000+1;	

			//g_ACode.EncodeAudioData ((char*)buffer,bufsize,m_cBufOut,&iOut);
			//t=sess.SendPacket(m_cBufOut,iOut,nPT,Mark,nTSTAMP);	
			
			t=sess.SendPacket(buffer,bufsize,nPT,Mark,nTSTAMP);	
		    if(t!=0)AfxMessageBox("can't sending");
			Sleep(5);
			Mark=false;			
		}
		(void) fflush( source ); 
		(void) fclose( source ); 
		AfxMessageBox("send success");
	WSACleanup();
	
}
示例#2
0
void* startsound(void *_ca)
{
	FILE *source=fopen("c://12pcm.wav","rb");
	if ( source == NULL )
	{
		cout<<"can't access the file"<<endl;
	}
//#ifdef win32
 	
//#endif	
	size_t bufRead  = 0;
	bool Mark=true;
	#define bufsize 1024
	BYTE buffer[bufsize];
	int t;
	RTPSession sess;
	
	t=sess.Create(5800);
	if(t!=0)cout<<"can't create"<<endl;
	bool sen;
	if(t==0){sen=true;}
	int nPT ;
	int nTSTAMP;
	sess.SetMulticastTTL(1);	//設定multicast封包TTL
	sess.AddDestination(ntohl(inet_addr("192.168.3.190")),portt);	//指定傳送目的端
	//sess.AddDestination(ntohl(inet_addr("192.168.25.79")),6900);
	if(t!=0) cout<<"can't add destination"<<endl;
	for (int jj=0;j<1000;j++) 
	{
	
	(void) fseek( source, 0, SEEK_SET );
		while(!feof(source))
		{
			bufRead = fread(buffer, sizeof(BYTE), bufsize, source ); 
			nPT=rand()%64+1;		
			nTSTAMP=rand()%1000+1;	
			t=sess.SendPacket(buffer,bufsize,nPT,Mark,nTSTAMP);	
		    if(t!=0)cout<<"can't sending"<<endl;
			Sleep(5);
			Mark=false;			
		}
	}
		(void) fflush( source ); 
		(void) fclose( source ); 
		cout<<("send success")<<endl;
	WSACleanup();
	return NULL;
}