Article View: borland.public.cppbuilder.internet.socket
Article #2489Multicast sample - receiving problem
From: swidmer
Date: Fri, 31 Mar 2006 02:55
Date: Fri, 31 Mar 2006 02:55
286 lines
8517 bytes
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;
}
//---------------------------------------------------------------------------
Technical Details
Message-ID:
<442c9af0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f32e24a6d09cf64f,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 30 Mar 2006 21:55:02 -0500 From: swidmer <swidmer@widmertime.com> User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Multicast sample - receiving problem Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 70.200.42.187 Message-ID: <442c9af0@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1143773936 70.200.42.187 (30 Mar 2006 18:58:56 -0700) Lines: 286 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail