IDUDPserver send data to a specific client ?

can udp server send data to a specific client that are on the same ip and port ?

i know that udp is connectionless but is there a way to send data to some clients based on some string matches ?

here is my client and server code


Server
unit UDPSRV;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent, IdUDPBase,
  IdUDPServer, IdGlobal, IdSocketHandle, Vcl.StdCtrls;

type
  Tudpservfrm = class(TForm)
    udpserver: TIdUDPServer;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure udpserverUDPRead(AThread: TIdUDPListenerThread;
      const AData: TIdBytes; ABinding: TIdSocketHandle);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure UpdateBindings;
  public
    { Public declarations }
  end;

var
  udpservfrm: Tudpservfrm;

implementation

{$R *.dfm}

procedure Tudpservfrm.Button1Click(Sender: TObject);
begin
 UpdateBindings;

 udpserver.Active := true;
end;

procedure Tudpservfrm.udpserverUDPRead(AThread: TIdUDPListenerThread;
  const AData: TIdBytes; ABinding: TIdSocketHandle);
begin
//
//memo1.Lines.Add(bytestostring(AData) + ABinding.PeerIP + ' : ' + intTostr(ABinding.PeerPort));
Athread.Server.Send(ABinding.PeerIP, ABinding.PeerPort, bytestostring(AData));





end;

procedure Tudpservfrm.UpdateBindings;
var
Binding: TIdSocketHandle;
begin
udpserver.DefaultPort := StrToInt(Edit1.Text);
udpserver.Bindings.Clear;
Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := StrToInt(Edit1.Text);
end;

end.

Open in new window


client

unit udpfrm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent, IdUDPBase,
  IdUDPClient, Vcl.StdCtrls, Vcl.ExtCtrls, IdUDPServer, IdGlobal, IdSocketHandle;

type
  TUDPClient = class(TForm)
    Button1: TButton;
    tmr1: TTimer;
    Memo1: TMemo;
    udpreciver: TIdUDPServer;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure tmr1Timer(Sender: TObject);
    procedure udpreciverStatus(ASender: TObject; const AStatus: TIdStatus;
      const AStatusText: string);
    procedure udpreciverUDPRead(AThread: TIdUDPListenerThread;
      const AData: TIdBytes; ABinding: TIdSocketHandle);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  UDPClient: TUDPClient;

implementation

{$R *.dfm}

procedure TUDPClient.Button1Click(Sender: TObject);
var
Binding: TIdSocketHandle;
begin

 if not udpreciver.Active then
  begin
    udpreciver.Active := True;

    udpreciver.Send('127.0.0.1',6754,edit1.Text);
  tmr1.Enabled := True;
  end;
end;

procedure TUDPClient.tmr1Timer(Sender: TObject);
begin
  try if udpreciver.Active then

   udpreciver.Send('127.0.0.1',6754,edit1.Text);

   except end;
end;

procedure TUDPClient.udpreciverStatus(ASender: TObject;
  const AStatus: TIdStatus; const AStatusText: string);
begin

memo1.Lines.Add(AStatusText);

end;

procedure TUDPClient.udpreciverUDPRead(AThread: TIdUDPListenerThread;
  const AData: TIdBytes; ABinding: TIdSocketHandle);
begin
memo1.Lines.Add(bytestostring(AData) + Abinding.IP);
end;

end.

Open in new window


now the server send back data to subscribed peerip/port , can i send data to a clients where the client id equal something same as tcp ? like assign a clientclass to the udp ?
madam marAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Sounds like you're trying to do some sort of UDP/TCP mashup.

You'd just require normal client side code to drop data for some clients.

Unsure how you'd try to arrange for specific clients to get specific packets using UDP + guarantee packets only reached some clients.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sinisa VukSoftware architectCommented:
Maybe you can use mac address of a client. At start, client will connect to server passing mac by own address, and server will use it later....
Client side app must filter messages based on local mac address....
Note: udp packets will come to client mixed - possible - not in a sequential way...as you might want.
0
madam marAuthor Commented:
i have deleted my comments because i consider this question as removed the answers is quite confusing this is not a tcp udp mashup how ever i have already did what i need by my self neither answers where a part of the real need .
simply your answer should be something simple like create a list to hold on the bindings that subscribed to the server  and loop for desired one is that wasn't simple enough to answer ?

Sinisa Vuk answer were something close but its not really the correct answer there is no need for mac address or what ever only a simple list that holds ip and port and use them later .
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Marked my solution as best, since poster is trying to somehow convert UDP packets to TCP.

Poster has stopped posting.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.