Delphi progamming

I had successfully created a simple midas client/server application.
I tested it with two computer which are connected by HUB. Let's called
them computer A and Computer B.
I used dcom connection at Client Application in the computer B to
connect to the server application at computer A. I set the computer's
name at DCOM connection as A

My question is how about if i want to install this application to another
LAN. This LAN has two computer also. Let's call them computer C and D and
I want C as Server and D as Client. The computer name for the DCOM
connection will be different. It is not A anymore.
Is it possible to automatically check the computer's name within
the network which act as server application?

Please don't ask me to change the Computer C'name to computer A's name.
smile22Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
simonetConnect With a Mentor Commented:
Smile22,

Here's the example of a unit that saves and retrieves the name of a server to/from the Registry, using Delphi's TRegIniFile.

You can, before opening the connection, call GetDCOMServer and use the other function to set/save the name of the server. Anyway, here it is:


unit uRegConfig;

interface

procedure SetDCOMServer(AName : string);
function GetDCOMServer : string;

implementation

uses Registry;

const
  sKEY = '\Simonetti\DCOMClient';
  sSECTION = 'Config';

procedure SetDCOMServer(AName : string);
var
  Reg : TRegIniFile;
begin
  Reg := TRegIniFile.Create(sKey);
  with Reg do
  try
     WriteString(sSECTION, 'ServerName', AName);
     CloseKey;
  finally
     free;
  end;
end;


function GetDCOMServer : string;
var
  Reg : TRegIniFile;
begin
  Reg := TRegIniFile.Create(sKey);
  with Reg do
  try
     Result := ReadString(sSECTION, 'ServerName', 'SUNSERVER');
     CloseKey;
  finally
     free;
  end;
end;

end.




Yours,

Alex
0
 
ckanetaCommented:
As far as I know, the client always has to know where the server is, so it pretty much has to be hard-coded in the application.
unless, of course, you let the user enter the name of the server at run-time
0
 
simonetCommented:
Move the computer name to a INI file or, even better, to the Registry. Before opening the DCOM connection, read the computer name from there.

This way, no matter in what computer you are, you can always configure the COM server by changing the INI file/Registry. You can also create a simple config application (in the control panel if you want).

Yours,

Alex
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
johnstonedCommented:
It is also possible to broker the connection.

By placing an object broker component onto your form, you can specify a list of server computers with which a connection is possible.  When the DCom component tries to connect, it will use whichever server the broker can see.

You can also use this component to load balance between mulitple servers on the same network.

Dave.
0
 
smile22Author Commented:
for simonet ,
how can i create INI file? can u give
an example?

for ckaneta,
thanks for ur comment

for jhonstoned,
thanks for ur comment
0
 
WinTrans2000ACommented:
Why don't send a Broadcast from your Client all over the Network and all Servers which receives the Message sends back an answer - and you have all your Servers (from your Subnet) within 1-2 seconds !
0
 
smile22Author Commented:
for winTrans2000A,
what do u mean by send Broadcast to the network? do u have any clear explanation about that?

for simonet,
i already test it but it seems doesn't work.
0
 
simonetCommented:
How it doesn't work? What is wrong?

Alex
0
 
smile22Author Commented:
is this source try to make one component
or this source i put it in my programming source code ?
0
 
simonetCommented:
This is a UNIT. You save that to a file called uRegConfig.pas, then add that file to your Delphi project.

Add the unit to the uses clause of any other unit from where you want to use it.

What this unit does is to export 2 functions, one for reading a user-defined computer name from Registy and another one to save the information back to the Registry.

In most cases, you'll only need the routine that reads the info, supposing your installation procedures already set the correct name of the server (the computer) in the key mentioned in the uRegConfig.pas unit.

BTW, you're allowed to change the key names and default values of the routines I sent you, as long as they are reading and writing to/from the very same place.

Alex
0
 
snoopy_SpyCommented:
Hi smile22
I have used this in a programm, and there it works like this :

The Server (sould be started before the client starts) opens a UDP-Port, where it listens for anything.
The first task of the client is, to send a broadcast message (Sending a UDP-message to Address 255.255.255.255) (that means, that this message is sent to every computer in the network !)
The Server than respons to this message, and the client get's within about 2 seconds all servers !

For the Broadcast thing i used FPiettes internet components (They are free and with source code !)

I can send you the code-parts if you like !
0
 
smile22Author Commented:
Adjusted points from 100 to 150
0
 
smile22Author Commented:
for simonet,
i will try ur suggestion first.
for snoppy spy,
how can i download that components?
can u send me the source code?
and i hope step by step to do it.
0
 
smile22Author Commented:
Answer accepted
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.