🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

[Indy / CBuilder6] Indy UDP messages received 3x

#4681
From: Zoetjuh
Date: Sun, 02 Jan 2005 20:28
89 lines
3775 bytes
Hi,

I've got some strange problem with the Indy components from Builder 6.
I'm got two little application.
1. Server Manager
2. Server(s)

The Manager will Broadcast a UDP Message to tell the server(s) to report in. The 
Server will answer the broadcast with a UDP Message directed to the IP of the 
Manager. Looking at a network monitor, indeed the Manager sends out a UDP 
Broadcast and the server answers this with it's own UDP Message.. Strangely, mu 
IdUDPServerRead triggers 3 times...

Does anyone know why?



Manager:
=========

(Broadcast part)
---
// Broadcast to PMS Agents
IdUDPServer->Broadcast("PMSAgent:00", agentPort);

(Receive event)
---

void __fastcall TTFormMain::IdUDPServerUDPRead(TObject *Sender, TStream *AData, 
TIdSocketHandle *ABinding)
{
        // Read data
        String myData = ReadStringFromStream(AData);
        ShowMessage(myData)
}


String __fastcall TTFormMain::ReadStringFromStream(TStream *Stream)
{
        // Create temperary buffer and Read the Stream
        char *lpszInBuffer = new char[Stream->Size + 1];
        Stream->ReadBuffer(lpszInBuffer, Stream->Size );

        // Set a 0nul terminator after the last received char
        lpszInBuffer[Stream->Size] = 0;

        // Assign temperary buffer to String and delete temperary buffer
        String myString = lpszInBuffer;
        delete lpszInBuffer;

        // Return AnsiString
        return myString;
}


Server
========

void __fastcall TUDPListener::myUDPRead(TObject *Sender, TStream *AData, 
TIdSocketHandle *ABinding)
{
        // Get Text
        String myText = ReadStringFromStream(AData);

        // Check if the received String contains text
        if (myText != "" && myText.SubString(0,9) == "PMSAgent:" )
        {
                // Init vars
                int myCommand = myText.SubString(10, 
myText.Length() ).ToIntDef(-1);

                // If the command turned out to be >= 0; update log
                if (myCommand != -1)
                {
                        logID = myCommand;
                        logMessage = "Command " + IntToStr(myCommand) + " 
received through UDP from: " + ABinding->PeerIP + ":"  + ABinding->PeerPort;
                        Synchronize( HandleThreadLogging );
                }

                // Check for "Report In" (00)
                if (myCommand == 00)
                        // Tell the manager we're here and ready to receive a 
connection on TCP level.
                        myUDPServer->Send(ABinding->PeerIP, ABinding->PeerPort, 
"PMSAgent:50");
        }
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <41d85960$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,3d8ffd4f4c4f8438,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Zoetjuh" <peter@i-hate-spam.zoetjuh.demon.nl>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: [Indy / CBuilder6] Indy UDP messages received 3x
Date: Sun, 2 Jan 2005 21:28:18 +0100
Lines: 91
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.161.4.111
Message-ID: <41d85960$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1104697696 82.161.4.111 (2 Jan 2005 12:28:16 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail