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?
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:
{code}
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;
{code}
--
Remy Lebeau (TeamB)
> 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?
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)