Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: UDP repeater?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Jan 13, 2015 9:13 AM Last Post By: Avraam Prisca
Avraam Prisca

Posts: 3
Registered: 1/20/14
UDP repeater?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 12, 2015 9:44 AM
I'm playing with UDP and I want to build a small app that acts as a repeater for SIP messages, something like this:

Originating client <----> UDP repeater <----> Destination server

A UDP server waits for messages from originating client, when it receives one, it send it using a UDP client to a destination server server.
If the destination server sends messages back, they need to be passed to the originating client.

I was looking into IDMappedPortUDP, but that one works by sending one message to the destination and then waiting for a message back.

In my situation the originating client sends one message and destination server could send multiple messages back and I have to pass them all to the originating client.

Can someone please point me in the right direction?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: UDP repeater?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 12, 2015 10:13 AM   in response to: Avraam Prisca in response to: Avraam Prisca
Avraam wrote:

In my situation the originating client sends one message and destination
server could send multiple messages back and I have to pass them all to
the originating client.

Can someone please point me in the right direction?

Indy does not have a specialized component that perfectly suits your requirement.
You will have to use the generic TIdUDPServer component and implement the
forwarding logic manually in its OnUDPRead event, where you will have access
to the PeerIP/PeerPort of the sender of each received packet. When you receive
a packet from a client, send it to the destination server. When you receive
a packet from a destination server, send it to the approproate client. You
will have to keep track of that association yourself in your own code.

--
Remy Lebeau (TeamB)
Avraam Prisca

Posts: 3
Registered: 1/20/14
Re: UDP repeater?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 12, 2015 10:22 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Indy does not have a specialized component that perfectly suits your requirement.
You will have to use the generic TIdUDPServer component and implement the
forwarding logic manually in its OnUDPRead event, where you will have access
to the PeerIP/PeerPort of the sender of each received packet. When you receive
a packet from a client, send it to the destination server. When you receive
a packet from a destination server, send it to the approproate client. You
will have to keep track of that association yourself in your own code.

Hi Remy,

I saw that this is exactly how IDMappedPortUDP works, but for each request waits only for one response. How would I make a udp client that connects to a server and sends a message, wait for multiple messages back?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: UDP repeater?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 12, 2015 2:12 PM   in response to: Avraam Prisca in response to: Avraam Prisca
Avraam wrote:

I saw that this is exactly how IDMappedPortUDP works, but for each
request waits only for one response. How would I make a udp client
that connects to a server and sends a message, wait for multiple
messages back?

The waiting logic is specific to the TIdMappedPortUDP component. It does
not apply to TIdUDPServer. You would not have to do any waiting at all,
just forward the packets as-is as you recieve them, eg:

procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const 
AData: TIdBytes; ABinding: TIdSocketHandle);
var
  DestIP: string;
  DestPort: TIdPort;
begin
  if ABinding.PeerIP = ServerIP then
  begin
    DestIP := AppropriateClientIP;
    DestPort := AppropriateClientPort;
  end else begin
    DestIP := ServerIP;
    DestPort := ServerPort;
  end;
  ABinding.SendTo(DestIP, DestPort, AData);
end;


--
Remy Lebeau (TeamB)
Avraam Prisca

Posts: 3
Registered: 1/20/14
Re: UDP repeater?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 13, 2015 9:13 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const 
AData: TIdBytes; ABinding: TIdSocketHandle);
var
  DestIP: string;
  DestPort: TIdPort;
begin
  if ABinding.PeerIP = ServerIP then
  begin
    DestIP := AppropriateClientIP;
    DestPort := AppropriateClientPort;
  end else begin
    DestIP := ServerIP;
    DestPort := ServerPort;
  end;
  ABinding.SendTo(DestIP, DestPort, AData);
end;


That works perfect. Thanks.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02