Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: how to use TIdIPMCastClient and TIdIPMcastServer properly


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


Permlink Replies: 13 - Last Post: Dec 15, 2017 6:19 AM Last Post By: madammar ellias
madammar ellias

Posts: 111
Registered: 8/17/17
how to use TIdIPMCastClient and TIdIPMcastServer properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 7:37 AM
i tried to search for a demo to understand how to communicate between clients and server but did not find much result about it

then i start creating a new project to create server app is this a correct way ?


unit msrver;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,
  IdIPMCastBase, IdIPMCastServer, IdSocketHandle, Vcl.StdCtrls;
 
type
  TForm3 = class(TForm)
    mserv: TIdIPMCastServer;
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form3: TForm3;
 
implementation
 
{$R *.dfm}
 
procedure TForm3.Button1Click(Sender: TObject);
begin
mserv.Binding.Port := StrToInt(Edit1.Text);
mserv.Binding.IP := '0.0.0.0';
mserv.Active := True;
 
//
end;
 
procedure TForm3.Button2Click(Sender: TObject);
begin
mserv.Binding.Broadcast('Test', 6754);
end;
 
end.
 


but i did not get how to make the client to connect to the server and communicate with other clients

here is the client code i think i am doing it very wrong
type
  TForm3 = class(TForm)
    mcsclient: TIdIPMCastClient;
    Connect: TButton;
    send: TButton;
    Memo1: TMemo;
    procedure mcsclientIPMCastRead(Sender: TObject;
      const AData: TIdBytes; ABinding: TIdSocketHandle);
    procedure ConnectClick(Sender: TObject);
    procedure sendClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form3: TForm3;
 
implementation
 
{$R *.fmx}
 
procedure TForm3.ConnectClick(Sender: TObject);
begin
// here i couldn't find ip property to set the client connect i found a bindings i amnot sure about setting the client properly 
mcsclient.Active := True;
end;
 
procedure TForm3.mcsclientIPMCastRead(Sender: TObject;
  const AData: TIdBytes; ABinding: TIdSocketHandle);
begin
//
memo1.Lines.Add(bytestostring(AData))
end;
 
procedure TForm3.sendClick(Sender: TObject);
begin
if mcsclient.Active then
begin
memo1.Lines.Add(intTostr(mcsclient.Bindings.Count));
 
end;
 
 
 
end;
 
end.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 11:19 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:
i tried to search for a demo to understand how to communicate between clients and server but did not find much result about it

There aren't any, that I am aware of.

then i start creating a new project to create server app is this a correct way ?

No.

mserv.Binding.Port := StrToInt(Edit1.Text);
mserv.Binding.IP := '0.0.0.0';

Use the TIdIPMCastServer's BoundIP/BoundPort properties instead to specify the IP/Port that the server is bound to locally for sending.

mserv.Active := True;

You don't need that.

mserv.Binding.Broadcast('Test', 6754);

Do not use the TIdSocketHandle.Broadcast() method in multicasting. Use the TIdIPMCastServer.Send() method instead, and set the TIdIPMCastServer's MulticastGroup and Port properties to your target multicast group IP/Port.

but i did not get how to make the client to connect to the server

There is no connection. In fact, the server is not aware of the clients at all.

and communicate with other clients

When you call TIdIPMCastServer.Send(), the data will be sent to every client that has subscribed to the specified multicast group IP/Port.

here is the client code i think i am doing it very wrong

Yes, you are.

procedure TForm3.ConnectClick(Sender: TObject);
begin
// here i couldn't find ip property to set the client connect i found a bindings i amnot sure about setting the client properly
mcsclient.Active := True;
end;

There is no IP to connect to. Add an entry to the client's Bindings collection for the local IP/Port that you want to receive data on (a multicast client can listen for data on multiple networks at the same time), and set the client's MulticastGroup property to the desired multicast group IP to listen to.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 8:02 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
now i am confused TIdIPMcastServer does not have onread event and TIdIPMCastClient Does .
TIdIPMCastClient does not have send property to start send data from client app .
how to send the data from one client to every one who subscribed on multicastgroub ?

is the TIdIPMcastServer should be on the client app ? and TIdIPMCastClient should be on the server side ?

thats how i set the server now

 
 
procedure TForm3.Button1Click(Sender: TObject);
begin
mserv.BoundPort := StrToInt(Edit1.Text);
mserv.BoundIP := '0.0.0.0';
mserv.MulticastGroup := '224.0.0.1';
mserv.Active := True;
 
//
end;
 
procedure TForm3.Button2Click(Sender: TObject);
begin
mserv.Send('Test', 6754);
end;

Client


procedure TForm3.ConnectClick(Sender: TObject);
var
Binding: TIdSocketHandle;
begin
mcsclient.DefaultPort := 6754;
mcsclient.Bindings.Clear;
Binding := mcsclient.Bindings.Add;
Binding.IP := '127.0.0.1';
Binding.Port := 6754;
mcsclient.Active := True;
end;
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 8:10 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

now i am confused TIdIPMcastServer does not have onread event and TIdIPMCastClient Does .

The roles are reversed. TIdIPMCastClient is the equivalent of TIdUDPServer, etc.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
madammar ellias

Posts: 111
Registered: 8/17/17
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 8:18 PM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:

The roles are reversed. cis the equivalent of TIdUDPServer, etc.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

i see now so the TIdIPMCastClient should work as a server and TIdIPMcastServer should work as a client

i have tried to reverse but i got port already in use when i try to start the client

server
procedure TForm3.ConnectClick(Sender: TObject);
var
Binding: TIdSocketHandle;
begin
mcsclient.DefaultPort := 6754;
mcsclient.Bindings.Clear;
Binding := mcsclient.Bindings.Add;
Binding.IP := '127.0.0.1';
Binding.Port := 6754;
mcsclient.MulticastGroup := '224.0.0.1';
mcsclient.Active := True;
end;


Client
procedure TForm3.Button1Click(Sender: TObject);
begin
mserv.BoundPort := StrToInt(Edit1.Text);
mserv.BoundIP := '127.0.0.1';
mserv.MulticastGroup := '224.0.0.1';
mserv.Active := True;
 
//
end;
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 1:41 AM   in response to: madammar ellias in response to: madammar ellias
Am 13.12.2017 um 05:51 schrieb madammar ellias:
Dave Nottage wrote:

The roles are reversed. cis the equivalent of TIdUDPServer, etc.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

i see now so the TIdIPMCastClient should work as a server and TIdIPMcastServer should work as a client

i have tried to reverse but i got port already in use when i try to start the client

Hello,

to check manually if a port is still free run cmd.exe
and enter this command:

netstat -p UDP

That should give you a list of all used ports for the UDP protocol.

Greetings

Markus
madammar ellias

Posts: 111
Registered: 8/17/17
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 4:01 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

Hello,

to check manually if a port is still free run cmd.exe
and enter this command:

netstat -p UDP

That should give you a list of all used ports for the UDP protocol.

Greetings

Markus

it is sure already in use because the server started on that port thats why i am asking because i think i am still doing it wrong
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 10:33 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

Binding.IP := '127.0.0.1';

You are binding TIdIPMCastClient to 127.0.0.1, ie the local loopback
adapter. As such, it won't be able to receive any multicast traffic
from the network at all. You need to bind it to the IP of an actual
network adapter that you want to receive data from, or to 0.0.0.0 to
bind to all network adapters.

mserv.BoundIP := '127.0.0.1';

Same thing here, too. Bind it to the IP of the network adapter that
you want to send data out from.

Also, you are not setting the TIdIPMCastServer.Port property. The
BoundPort property is what the socket is bound to locally (the source
port for datagrams). The Port property is the port where
TIdIPMcastServer.Send() sends data to (the destination port for
datagrams).

Also, if you are running the client and server on the same machine, you
are likely binding them to the same local IP/Port, which is why you are
getting the "already in use" error. So make sure the TIdIPMCastServer's
BoundIP/BoundPort properties and the TIdIPMCastClient's Binding.IP/Port
properties are not the same values when running on the same machine.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 7:08 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

You are binding TIdIPMCastClient to 127.0.0.1, ie the local loopback
adapter. As such, it won't be able to receive any multicast traffic
from the network at all. You need to bind it to the IP of an actual
network adapter that you want to receive data from, or to 0.0.0.0 to
bind to all network adapters.

--
Remy Lebeau (TeamB)

i tried to do the following i got socket error

TIdIPMCastClient Socket Error # 10065No route to host.

procedure TForm3.Button1Click(Sender: TObject);
var
Binding: TIdSocketHandle;
begin
mcsclient.DefaultPort := strToint(edit1.Text);
mcsclient.Bindings.Clear;
Binding := mcsclient.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := strToint(edit1.Text);
mcsclient.MulticastGroup := '224.0.0.1';
mcsclient.Active := True;
end;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 7:54 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i tried to do the following i got socket error

TIdIPMCastClient Socket Error # 10065No route to host.

That error is WSAEHOSTUNREACH, which you should not be getting from
TIdIPMCastClient as it is just a receiver and not a sender. There is
no host to reach.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 10:28 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

now i am confused TIdIPMcastServer does not have onread event and
TIdIPMCastClient Does . TIdIPMCastClient does not have send
property to start send data from client app .

Multicasting is one-directional, 1-to-many. The server sends data to
interested clients, not the other way around. That is why
TIdIPMcastServer has a Send() method and TIdIPMCastClient has an OnRead
event.

how to send the data from one client to every one who subscribed on
multicast groub ?

The client needs its own TIdIPMCastServer to send data with.

is the TIdIPMcastServer should be on the client app ?

Yes.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 8:35 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
i have no problem using 0.0.0.0 as a binding ip in other server components , only multicast raised this . but any way

changed back to local ip 127.0.0.1 client has started. now this client multicast group is set to 224.0.0.1

each other server will subscribed to that Client with different group number.
to be able to get specific data to that group while sending back the client is already set to 224.0.0.1 what if the other senders have 225.0.0.2 or 223.0.0.4 etc..
i strongly need code sample for this whole idmulticast to understand it clearly its really difficult to collect the puzzle
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 3:53 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i have no problem using 0.0.0.0 as a binding ip in other server
components , only multicast raised this .

Multicast isn't a typical socket setup. Have you tried binding to the
IP of a specific LAN adapter instead of to 0.0.0.0?

changed back to local ip 127.0.0.1 client has started. now this
client multicast group is set to 224.0.0.1

By default, multicast traffic doesn't work over 127.0.0.1, because the
OS uses an external LAN adapter by default to send multicast traffic.
If you bind to 127.0.0.1, you can't send data to a multicast group IP
(since it is not the loopback IP) unless you add an entry for
multicast->loopback in the OS's routing tables.

each other server will subscribed to that Client with different
group number. to be able to get specific data to that group while
sending back the client is already set to 224.0.0.1 what if the other
senders have 225.0.0.2 or 223.0.0.4 etc..

TIdIPMCastServer can only send to 1 group at a time, so you would have
to either:

- use separate TIdIPMCastServer instances for each group

- change the TIdIPMCastServer.MulticastGroup in between sends

i strongly need code sample for this whole idmulticast to understand
it clearly

I don't have any.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: how to use TIdIPMCastClient and TIdIPMcastServer properly [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 15, 2017 6:19 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

I don't have any.

--
Remy Lebeau (TeamB)

any other alternative than udp/multicast that i have to test that can suite a multi sending needs .
i am trying to work hard to solve that streaming problem that i have ... unfortunately i am not that expert to find a suitable way and the resources online about udp in delphi are very limited
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02