🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #325

(INDY) UDP binding and broadcast

#325
From: JohnG
Date: Tue, 15 Apr 2008 14:32
138 lines
4471 bytes
Hi,

I am having issues with UDP binding and UDP broadcasts. It 
appears that the binding is not enforced when broadcasting 
messages. When I bind to an IP\NIc in a multi nic system
the message is sent across both connections and received by 
connected computers.

I have include the system setup and sample app I am using to 
verify the results.

Thanks,

JohnG








System setup is as follows, there are no switches or hubs:

System 1
--------
Nic #1 10.90.80.41 / 255.255.255.0 (connects to system 2)
Nic #2 unplugged
Nic #3 10.90.90.6  / 255.255.255.0 (connects to system 3)

System 2
--------
Nic #1 10.90.80.42 / 255.255.255.0   connects to system 1
Nic #2 unplugged
Nic #3 unplugged



System 3
--------
Nic #1 10.90.90.5 /255.255.255.0 connects to system 1


Sample code is :
//
//header file
//
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdUDPBase.hpp>
#include <IdUDPServer.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TEdit *EditBindIP;
	TButton *ButtonBindIP;
	TButton *ButtonSendMessage;
	TEdit *EditMessage;
	TIdUDPServer *IdUDPServer;
	TMemo *Memo1;
	void __fastcall ButtonSendMessageClick(TObject *Sender);
	void __fastcall ButtonBindIPClick(TObject *Sender);
	void __fastcall IdUDPServerUDPRead(TObject *Sender, TStream *AData,
          TIdSocketHandle *ABinding);
private:	// User declarations
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

//
//source file
//

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonSendMessageClick(TObject *Sender)
{
   if(!IdUDPServer->Active)
      ShowMessage("UDP not enabled.");

   IdUDPServer->Broadcast(EditMessage->Text,40);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonBindIPClick(TObject *Sender)
{
	IdUDPServer->Active       = false;
	IdUDPServer->Bindings->Clear();

	TIdSocketHandle *pBinding = IdUDPServer->Bindings->Add();
	pBinding->IP              = EditBindIP->Text;
	pBinding->Port            = 40;
	IdUDPServer->Active       = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdUDPServerUDPRead(TObject *Sender, TStream *AData,
	  TIdSocketHandle *ABinding)
{
   AnsiString Text;

   if(AData->Size > 0)
   {
	  int iSize = AData->Size;
	  Text.SetLength(iSize);
	  AData->Read(Text.c_str(),iSize);

	  Memo1->Lines->Add("UDP received " + Text + " from " + ABinding->PeerIP);
   }
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <4804bc99@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,7b3ef48fe39eea8e,start
X-Google-Attributes: gid11508e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "JohnG" <whatis@email.com>
Sender: "JohnG" <whatis@email.com>
Reply-To: "JohnG" <whatis@email.com>
Subject: (INDY) UDP binding and broadcast
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 138.11.0.153     
X-Forwarded-For: unknown
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4804bc99@newsgroups.borland.com>
Date: 15 Apr 2008 07:32:57 -0700
X-Trace: newsgroups.borland.com 1208269977 207.105.83.66 (15 Apr 2008 07:32:57 -0700)
Lines: 141
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail