Solved

Delphi progamming

Posted on 2000-05-16
14
229 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:smile22
14 Comments
 
LVL 3

Expert Comment

by:ckaneta
ID: 2815983
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
 
LVL 15

Expert Comment

by:simonet
ID: 2816090
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
 

Expert Comment

by:johnstoned
ID: 2816735
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:smile22
ID: 2817583
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
 
LVL 15

Accepted Solution

by:
simonet earned 150 total points
ID: 2818543
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
 

Expert Comment

by:WinTrans2000A
ID: 2820477
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
 

Author Comment

by:smile22
ID: 2824528
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
 
LVL 15

Expert Comment

by:simonet
ID: 2825459
How it doesn't work? What is wrong?

Alex
0
 

Author Comment

by:smile22
ID: 2828080
is this source try to make one component
or this source i put it in my programming source code ?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2828089
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
 

Expert Comment

by:snoopy_Spy
ID: 2830398
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
 

Author Comment

by:smile22
ID: 2830560
Adjusted points from 100 to 150
0
 

Author Comment

by:smile22
ID: 2830561
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
 

Author Comment

by:smile22
ID: 2884239
Answer accepted
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question