![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
ASTA User's Guide
Topics Connecting Clients & Servers Managing the Login process & Customizing the Login Process
Topic Discussions Connecting Clients & Servers
ASTA is based on the TCP/IP protocol. In order to use it successfully, you don't need to know a lot about TCP/IP but it helps to know some basic principles. AstaServers and AstaClients "speak" to one another using sockets. A socket is the combination of an IP Address and a Port. The following socket, 204.125.124.10:3245, has an IP address of 204.125.124.10 and a port of 3245. An AstaServer starts a socket that can handle multiple connections. When
you look in the object inspector for an AstaServerSocket, you will notice
that there is not an Address property but there is When you create your clients, you must specify the Address and the Port of the server. In this case, you would set that AstaClientSocket to 204.125.124.10 for the address and 9000 for the Port. If you wish to see design time data when writing your application, you must specify the correct address and port and the server must be running! The AstaClientSocket's Host property can be used for DNS names. If you are using DNS and your server has a name you can enter "YourServerName.Com" in the Host property. If that field is used, it will override the value in the Address property. You must specify the port whether you use the Host property or the Address property. For detailed information on the OnConnect, OnDisconnect and OnAccept events, please see Borland's help file entries for the TClientSocket and TServerSocket. There is a bit of counter-intuitive behavior at the server that can be confusing for the novice; the OnAccept event, not the OnConnect event, is the first point where the server actually has meaningful access to the client connection. Special Notes for the server: Special Notes for the client:
ASTA provides facilities to help you manage the client login process. The Client's AutoLoginDlg property is the key to the login process. The AutoLoginDlg can be set to one of three selections:
No matter which option is selected, the AstaClientSocket's UserName, Password and ApplicationName are transmitted to the Server (if ltLoginDlg is selected, the UserName and Password properties are set to the input values entered by the user, then transmitted). If ltLoginDlg or ltLoginNoDlg have been selected, then you must code the AstaServerSocket's OnClientLogin event. procedure TForm1.AstaServerSocket1ClientLogin(Sender: TObject; UserName,
Password, AppName: String; var Verified: Boolean);
var
AllowUserIn : Boolean;
begin
//Do your stuff here -- typically lookup values in a database
if AllowUserIn then Verified := True else Verified := False;
end;
If verified is set to True, then the client will be connected to the server. Whether verified is set to True or False, that result will be transmitted back to the client. Whether or not you code the AstaClientSocket's OnLoginAttempt event handler will dictate what happens next. If you do not code the event handler and then the client will either continue normally if the result was true, or terminate immediately if it is false. If you would like to take other action -- possibly allow the user three login attempts before terminating the application, or perhaps showing a menu only after the user has been verified, then you can code the OnLoginAttempt event. procedure TForm1.AstaClientSocket1LoginAttempt(Sender: TObject; ClientVerified: Boolean); begin //Track login attempts, kill app if they goof three times Inc(FLoginCounter); if (FLoginCounter >=3) and not(ClientVerified) then begin Application.Terminate; end else if ClientVerified then // good login action goes here MainMenu1.Items[0].Visible := True else // bad login action goes here -- reprompt login dialog* AstaClientSocket1.AttemptClientLogin; end; * the AutoLoginDlg's property is set to ltLoginDlg If you wish to track the users that have been logged into the server, assign a TCheckListBox to the AstaServerSocket's UserCheckList property.
Many developers want to create a custom login screen for their users. A custom login provides you with the opportunity to present a promotional splash screen or even an advertising opportunity. If you select the caCustomConnect option of the AstaClientSocket's ConnectAction property, then you can customize a login screen. If you select this option, you can display your login screen from within the OnCustomConnect event handler. In that event handler, you have access to the AstaClientSocket and all of its properties. You must set the Address and Port property or the Host and Port property. Those properties become your responsibility when implementing a custom login. procedure TForm1.AstaClientSocket1CustomConnect(Sender: TObject);
ASTA provides great flexibility for encryption. In addition to giving you complete control over any encryption scheme that you may wish to implement, ASTA ships with built-in encryption that you can activate without writing a single line of code -- instant encryption! To enable the built-in encryption simply set the
AstaClientSocket and the AstaServerSocket's Encrypt property to "etAstaEncrypt"
and recompile (you must recompile the server and the client, otherwise
they will be out-of-synch). The etAstaEncrypt algorithm is quite simple
but it will discourage casual lurkers (keep in mind that most security
breaches are the result of social engineering, not highly skilled hacking).
ASTA passes the message into the event handlers as a String type. If your encryption library is string based you code would look like the following calls. procedure TForm1.AstaServerSocket1Encrypt(Sender: TObject; var S: String); begin S := YourEncryptionRoutineHere(S); end; procedure TForm1.AstaServerSocket1Decrypt(Sender: TObject; var S: String); begin S := YourDecryptionRoutineHere(S); end; If, however, you have a streams based encryption library, you would need to take some extra steps. ASTA provides a couple of functions to help you manage String and Stream conversions. To use these functions, you must add AstaUtil to the unit's Uses clause. function NewStringToStream(S: AnsiString):
TMemoryStream; The following code shows how you would use these calls to encrypt the message. procedure TForm1.AstaServerSocket1Encrypt(Sender: TObject; var S: String); var MyStream : TMemoryStream; begin MyStream := TMemoryStream.Create; MyStream := NewStringToStream(S) YourEncryptionRoutineHere(MyStream); S := StreamToString(MyStream); MyStream.Free; end;
ASTA provides great flexibility for compression. In addition to giving you complete control over any compression library that you may wish to implement, ASTA ships with built-in compression that you can activate without writing a single line of code -- instant compression! To enable the built-in compression simply set the AstaClientSocket and the AstaServerSocket's Compress property to "acAstaCompress" and recompile (you must recompile the server and the client, otherwise they will be out-of-synch). If you wish to implement your third-party compression routines, or perhaps your own compression routines, you must use the OnCompress and OnDecompress event handlers. Your routines must be implemented on the Client and the Server. For further details, see the Encryption explanation, the OnCompress and OnDecompress event handlers are mirror the functionality of the OnEncrypt and OnDecrypt routines.
ASTA provides you with the ability to automatically update AstaClients. Starting with ASTA v 1.91, if you have distributed 50 copies of an AstaClient as version 1.0, you can automatically update them by registering a later AstaClient version, say 1.1 or 2.0, at the server. When a user of version 1.0 logins into the server, he or she will be automatically updated to the latest version of your software. The following narrative describes how you can add AutoUpdate features to your ASTA projects. When you create an AstaClient program, simply fill in the AstaClientSocket.ApplicationName and ApplicationVersion properties. For our example, lets call the our AstaClient program "MyClient" and assign "1.0" to the ApplicationVersion property and "MyClient" to the ApplicationName property.
Now you can distribute the application, confident that you can update it with ease. When you have a new version of your software, you simply supply a later version number. If your first release went out as version 1.0, make your update 1.1 or 2.0.
After you compile the program, take the resulting executable file and copy it to the server. If your executable is MyClient.exe, you might want to call it MyClient11.exe so that you can differentiate it from future releases. At the server, you simply need to call one method to register your new file. In the example below, I have added a TMenu to my AstaServer and I use a "Register Update Client" menu option to call RegisterClientAutoUpdate. procedure TForm1.RegisterUpdateClient1Click(Sender:
TObject); At run time, you can simply register your new executable in the dialog box picture below.
When the client logs in, a dialog box with a progress bar pops up. It informs them about the need for an update and then the progress bar tracks the status of the update. If you wish to write a log or record the updates to a database, the AstaServerSocket provides an OnAstaClientUpdate event handler that allows you to record the UserName, ApplicationName and version numbers involved in the Update process: procedure TForm1.AstaServerSocket1AstaClientUpdate(Sender:
TObject; UserName, AppName, OldVer, NewVer: String); Download a Delphi version of an AutoUpdate Tutorial. Special Notes Be certain that you do not confuse your files. If you wish to update the 1.0 version with the 2.0 version, then be certain that the 2.0 version is the executable that you register at the server. If you accidentally register the 1.0 version, you will cause an infinite update loop!
The ASTA Remote Directory features allow you to "publish" a server directory. When a server publishes a directory, AstaClients can open files from and save files to that remote server directory. This is a convenient feature, but it has limitations and should be used with care. You should not publish a directory with thousands of files and dozens of subdirectories for performance reasons, and for security reasons you should not publish a root directory or other sensitive information. We recommend that you create a stand-alone directory dedicated to the sole task of publishing and accepting files. Like many ASTA features, this one is a tandem implementation, you must coordinate actions on the Server and the Client sides or the feature will not operate properly. To set up a server, you must drop a TAstaServerDirectory
object onto the server application. Then you . must assign the object to the AstaServerSocket.DirectoryPublisher property. Once that property is assigned, you can call the AstaServerSocket.PubishServerDirectories method -- in the sample project I added a menu that allows the user to configure the server at run time.
Design-Time Security
ASTA provides powerful design time features by
allowing a developer to access currently running AstaServers. This access
does not require a password, a convenience that allows you to have easy
access to your design time data without having to type in usernames and
passwords at every turn. But it also opens up a potential security hole.
Other ASTA developers, if they knew the IP Address and the Port of your
AstaServer, would be able to gain access to your database if they were
so inclined. One simple step that you can take to help avoid this problem
is to switch your AstaServers from the default Port of 9000 to a different
number above 1024. Copyright @ 2000, ASTA Technology
Group. For more information, contact info@astatech.com
|