🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages Started by Lapo Guidi Tue, 07 Feb 2006 13:50
UDP Client/Server broadcasting
#2686
Author: Lapo Guidi
Date: Tue, 07 Feb 2006 13:50
51 lines
2043 bytes
Hi all,
I coded a simple UDP Client/Server application.
The problem I have is that when I broadcast using the Client, the OnUDPRead of the Server is fired 2 times, so I receive every data doubled.
If I send datas to a target IP all works fine.
This is a snip of code:

Client--
---
Properties:
Active = true
BroadcastEnabled = true
BufferSize = 8192
Host = (empty string)
Port = 9999
ReceivedTimeout = -2
---
Send function used
UDPClient->Broadcast(Memo1->Lines->Text, 9999);

---
Server
---
Properties:
Active = true
Bindings = (empty)
BroadcastEnabled = true
BufferSize = 8192
DefaultPort = 9999
ThreadedEvent = false
---
Receive function used
void __fastcall TForm1::UDPServerUDPRead(TObject *Sender, TStream *AData,
	  TIdSocketHandle *ABinding)
{
	AnsiString Text="";

	if(AData->Size>0) {
	        int Len=AData->Size-AData->Position;
		Text.SetLength(Len);
		AData->Read(&Text[1], Len);
		Memo1->Lines->Add(Text);
	}
}
---
This function is called twice.

Can anybody help me?
Thanks in advance

Lapo
Re: UDP Client/Server broadcasting
#2687
Author: Remy Lebeau (TeamB)
Date: Tue, 07 Feb 2006 18:19
18 lines
1708 bytes
"Lapo Guidi" <lapoguidi@antispam.com> wrote in message
news:43e8b39a$1@newsgroups.borland.com...

> The problem I have is that when I broadcast using the Client, the
> OnUDPRead of the Server is fired 2 times, so I receive every
> data doubled.

Do you have multiple NIC cards on the client and/or server?  If so, then on
the server, you are definately binding to all available NIC cards, since you
left the Bindings collection empty.  Try adding an entry to the Bindings
collection and set its IP property to a specific NIC card only.  When the
client broadcasts, all of the IPs are likely receiving the packet, which is
why you get multiple events.  If you bind to specific IPs only, you won't
get so many events.


Gambit
Re: UDP Client/Server broadcasting
#2689
Author: Lapo
Date: Wed, 08 Feb 2006 12:00
13 lines
1162 bytes
Hi Remy,

>Do you have multiple NIC cards on the client and/or server?  
No I haven't 2 NIC cards, but I have 2 differents IPs in the same board.
I tried to bind to an IP then I tried to remove one IP, but the problem still there.

How could I fix that? Any other suggestions?

Thanks anyway Remy

Greets,
Lapo
Re: UDP Client/Server broadcasting
#2690
Author: Bob Gonder
Date: Wed, 08 Feb 2006 15:05
11 lines
1371 bytes
Lapo wrote:

>How could I fix that? Any other suggestions?

I see 2 ways to get around that.

1) add a time field in front of the text. The server could then ignore
duplicate time-stamped messages from the same ip.

2) switch to TCP/IP, which is friendlier to network traffic, and also
works over VPNs..
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