Board index » cppbuilder » Sending and using MemoryStream with Indy?
A.Gil
![]() CBuilder Developer |
Sending and using MemoryStream with Indy?2004-06-18 07:16:40 AM cppbuilder10 Hi: I'm using some Delphi voice components (VC Components by LakeOfSoft) for audio processing(recording, encoding,resampling, playback etc..) I'm trying to send the voice data using a stream over Indy sockets, but I'm sure I'm doing something wrong, and I can't get it working. Maybe I'm doing something bad with streams, but don't know what. Can someone give me some help? Thanks a lot On Server Side: [...] TMemoryStream* ReceivedStream = new TMemoryStream(); [...] void __fastcall TDMVoz::IdTCPServer1Execute(TIdPeerThread *AThread) { int size = AThread->Connection->ReadInteger(false); AThread->Connection->ReadStream(ReceivedStream, -1, false); codecOut->write(StreamRecibido, size, NULL); //feed the Delphi audio //codec with the stream } //--------------------------------------------------------------------------- On Client Side: [...] TMemoryStream* StreamVoice; StreamVoice = new TMemoryStream; [...] void __fastcall TDMVoz::codecInDataAvailable(unavclInOutPipe *sender, Pointer data, DWORD len) { StreamVoice->Clear(); StreamVoice->Write(data, len); //Write data to memory stream if(!bIsServer) { //If we are "client" //We pass the data to Indy client socket if(IdTCPClient1->Connected()) { IdTCPClient1->WriteInteger(len, false);//Write stream length //Write the stream IdTCPClient1->WriteStream(StreamVoice, true, true, 0); } } else { //we are the server TList* pList = IdTCPServer1->Threads->LockList(); TIdPeerThread* Thread; try { for (int i = 0; i < pList->Count; i++) { //Write the stream to all the threads in TCPServer(only 1) Thread = (TIdPeerThread*)pList->Items[i]; Thread->Connection->WriteStream(StreamVoice, true, true, 0); } } __finally { IdTCPServer1->Threads->UnlockList(); } } } //--------------------------------------------------------------------------- |