Solved

Delphi progamming

Posted on 2000-05-16
14
227 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now