🚀 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 swidmer Fri, 31 Mar 2006 02:55
Multicast sample - receiving problem
#2489
Author: swidmer
Date: Fri, 31 Mar 2006 02:55
286 lines
8517 bytes
I am having difficulty building a small multicast server and receiver. I 
am using Cbuilder 6 service pack 4, and Indy 9.0.18.

The server uses the IdIPMCastServer component and the receiver uses the 
IdIPMCastClient component.

For the server a form is created with the server component, a timer and 
3 text fields for settings (Multicast address, Port, and Curent Time) 
and 3 buttons (Start Sending, Stop Sending, Exit).

The receiver, built as a separate project is placed on a form with 3 
text fields (Current time - Received info, Multicast ip, port) and 3 
buttons (Start listening, Stop listening, Exit).

The immediate problem is I never seem to trigger the OnIPMCastRead event:

The Receive form is defined:
object Form1: TForm1
   Left = 275
   Top = 541
   Width = 1142
   Height = 656
   Caption = 'Form1'
   Color = clBtnFace
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
   Font.Height = -11
   Font.Name = 'MS Sans Serif'
   Font.Style = []
   OldCreateOrder = False
   PixelsPerInch = 96
   TextHeight = 13
   object Tod: TEdit
     Left = 72
     Top = 16
     Width = 121
     Height = 21
     TabOrder = 0
     Text = 'Tod'
   end
   object ListenIP: TEdit
     Left = 72
     Top = 56
     Width = 121
     Height = 21
     TabOrder = 1
     Text = 'ListenIP'
   end
   object ListenPort: TEdit
     Left = 72
     Top = 96
     Width = 121
     Height = 21
     TabOrder = 2
     Text = 'ListenPort'
   end
   object Listen: TButton
     Left = 208
     Top = 32
     Width = 75
     Height = 25
     Caption = 'Listen'
     TabOrder = 3
     OnClick = ListenClick
   end
   object Exit: TButton
     Left = 296
     Top = 80
     Width = 75
     Height = 25
     Caption = 'Exit'
     TabOrder = 4
     OnClick = ExitClick
   end
   object Stop: TButton
     Left = 296
     Top = 32
     Width = 75
     Height = 25
     Caption = 'Stop Listening'
     TabOrder = 5
     OnClick = StopClick
   end
   object IdIPMCastClient1: TIdIPMCastClient
     Bindings = <
       item
         IP = '127.0.0.1'
         Port = 5656
       end>
     DefaultPort = 5656
     MulticastGroup = '224.0.0.1'
     OnIPMCastRead = IdIPMCastClient1IPMCastRead
     Left = 8
     Top = 16
   end
end

The source for this form is:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "recvmcast.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "IdIPMCastBase"
#pragma link "IdIPMCastClient"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ExitClick(TObject *Sender)
{
  Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListenClick(TObject *Sender)
{
IdIPMCastClient1->MulticastGroup=ListenIP->Text;
IdIPMCastClient1->DefaultPort=ListenPort->Text.ToInt();
IdIPMCastClient1->Active=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StopClick(TObject *Sender)
{
IdIPMCastClient1->Active=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdIPMCastClient1IPMCastRead(TObject *Sender,
       TStream *AData, TIdSocketHandle *ABinding)
{
char data[40];
if (AData->Size>0)
   {
     AData->ReadBuffer(data,AData->Size);
     Tod->Text=data;
   }
}
//---------------------------------------------------------------------------

I believe base on reading the information on the Indy web site, Indy in 
depth, reviewing the source -although not fully understanding it..the 
above procedure would be fired when ever a udp-multicat packet arrives 
at the computer.  Since this is being run on the same computer as the 
server I set the listener to monitor 127.0.0.1, to no avail.  anyhelp 
would be appreciated to help me to understand what I'm doing wrong.

Below please find my sample source for the server side:

object Form1: TForm1
   Left = 192
   Top = 114
   Width = 1142
   Height = 656
   Caption = 'Form1'
   Color = clBtnFace
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
   Font.Height = -11
   Font.Name = 'MS Sans Serif'
   Font.Style = []
   OldCreateOrder = False
   PixelsPerInch = 96
   TextHeight = 13
   object CastAddr: TEdit
     Left = 48
     Top = 8
     Width = 233
     Height = 21
     TabOrder = 0
     Text = 'mcast addr'
   end
   object OKButton: TButton
     Left = 304
     Top = 16
     Width = 75
     Height = 25
     Caption = 'OK to send'
     TabOrder = 1
     OnClick = OKButtonClick
   end
   object CastPort: TEdit
     Left = 48
     Top = 40
     Width = 233
     Height = 21
     TabOrder = 2
     Text = 'CastPort'
   end
   object TimeDisplay: TEdit
     Left = 48
     Top = 72
     Width = 233
     Height = 21
     TabOrder = 3
     Text = 'TimeDisplay'
   end
   object ExitButton: TButton
     Left = 392
     Top = 64
     Width = 75
     Height = 25
     Caption = 'Exit'
     TabOrder = 4
     OnClick = ExitButtonClick
   end
   object StopSendButton: TButton
     Left = 400
     Top = 16
     Width = 75
     Height = 25
     Caption = 'Stop Sending'
     TabOrder = 5
     OnClick = StopSendButtonClick
   end
   object IdIPMCastServer1: TIdIPMCastServer
     MulticastGroup = '224.0.0.1'
     Port = 0
     TimeToLive = 2
   end
   object Timer1: TTimer
     OnTimer = Timer1Timer
     Top = 32
   end
end

Source:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "IdIPMCastBase"
#pragma link "IdIPMCastServer"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::OKButtonClick(TObject *Sender)
{
IdIPMCastServer1->MulticastGroup=CastAddr->Text;
IdIPMCastServer1->Port=CastPort->Text.ToInt();
IdIPMCastServer1->Active=true;
IdIPMCastServer1->Send(TimeToStr(Time()));

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
TimeDisplay->Text=TimeToStr(Time());
if (IdIPMCastServer1->Active==true)
         {
            IdIPMCastServer1->Send(TimeToStr(Time()));
            if 
(TimeDisplay->Color==clWindow||TimeDisplay->Color==clBlue)TimeDisplay->Color= 
clYellow;
            else TimeDisplay->Color=clBlue;
         }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ExitButtonClick(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StopSendButtonClick(TObject *Sender)
{
IdIPMCastServer1->Active=false;
TimeDisplay->Color=clWindow;
}
//---------------------------------------------------------------------------
Re: Multicast sample - receiving problem
#2508
Author: swidmer
Date: Thu, 06 Apr 2006 04:21
5 lines
1146 bytes
The big issue turns out to be you must have a router capable of 
multicast fowarding.  Loopback does not appear to actually loopback with 
in the same pc as it normally would with a tcp connection.

swidmer
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