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?
 
David FavorConnect With a Mentor Linux/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
 
Sinisa VukCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.