🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages Started by Shiu-Huei-Huang Thu, 08 Nov 2007 03:43
Multicast receiver program problem !!
#784
Author: Shiu-Huei-Huang
Date: Thu, 08 Nov 2007 03:43
50 lines
2126 bytes
I write a multicast receiver program !
But It doesnt work!
Who can tell me where does it go wrong ?
thanks

this is the source code using BCB 6 AND INDY 9 !



#include <vcl.h>
#pragma hdrstop

#include "RcvForm1Main.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma link "IdIPMCastBase"
#pragma link "IdIPMCastClient"
#pragma resource "*.dfm"
TRcvForm1 *RcvForm1;

//--------------------------------------------------------------------------
-

void __fastcall TRcvForm1::StartBtn1Click(TObject *Sender)
{
 RcvLogMemo1->Clear();
 IdIPMCastClient1->MulticastGroup="225.0.30.30";
 IdIPMCastClient1->DefaultPort=3000;
 IdIPMCastClient1->BufferSize=8192;
 IdIPMCastClient1->Active=true;
}
//--------------------------------------------------------------------------
-

void __fastcall TRcvForm1::CloseBtn1Click(TObject *Sender)
{
 IdIPMCastClient1->Active=false;
 Application->Terminate();
}
//--------------------------------------------------------------------------
-

void __fastcall TRcvForm1::IdIPMCastClient1IPMCastRead(TObject *Sender,
      TStream *AData, TIdSocketHandle *ABinding)
{
 char RcvMsg[8192];
 AData->ReadBuffer(RcvMsg,sizeof(RcvMsg));
 RcvLogMemo1->Lines->Add(AnsiString(RcvMsg));
}
Re: Multicast receiver program problem !!
#785
Author: Remy Lebeau (TeamB)
Date: Thu, 08 Nov 2007 04:12
22 lines
1708 bytes
"Shiu-Huei-Huang" <huei.huan@msa.hinet.net> wrote in message
news:473285e6$1@newsgroups.borland.com...

> I write a multicast receiver program !
> But It doesnt work!

Just saying that something does not work says nothing about the actual
problem you are having with it.  You need to be more specific.

>  char RcvMsg[8192];
>  AData->ReadBuffer(RcvMsg,sizeof(RcvMsg));
>  RcvLogMemo1->Lines->Add(AnsiString(RcvMsg));

You are not checking the return value of ReadBuffer() or the Size property
of AData to know how many bytes have actually been received.  You are also
not taking into account that the OnRead event is triggered in the context of
a worker thread, not the main thread, so your access to the TMemo is not
thread-safe.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads