KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Automatically Registering Clients at Startup with 4D Server v6.5.x
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: March 17, 2000
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

This option, available beginning with version 6.5.x, allows you to automatically register 4D Clients as soon as they connect to a 4D Server database. Once "registered", a client can execute anything requested by another client or by the server itself. You can define this option in the workstation's or server's properties. In both cases, this option is applied to each client workstation that connects to the database (this option is stored in the database's structure file).

Note: This option is selected by default in databases created with 4D version 6.5. In databases created with a previous version of 4D, it is not selected by default.

To automatically register clients:

1) In the Database Properties dialog box, click on the "Connections" tab

2) Select the "Register Clients at Startup" option and accept the dialog box.

Now, all the clients that connect to the database will be automatically registered. However, it is necessary to quit and restart the clients already connected for this option to take effect. This option is mainly to be used by the On 4D Client function in the Method execution dialog box in the User mode. To create a sophisticated system to distribute tasks between clients, it is preferable that you use the commands that have been created for this purpose. Before the release of 4D Server 6.5.x the only way to register a client was procedurally.

REGISTER CLIENT (clientName {; period} {; *})
























Parameters



Type



Description



clientName



String



Name of the 4D Client session



period



Longint



Server's interrogation period (in seconds)



-



-



Local process


This command "registered" a 4D Client station with the name specified in clientName on 4D Server, so as to allow other clients or eventually 4D Server (by using stored methods) to execute methods on it by using the EXECUTE ON CLIENT command. Once it is registered, a 4D Client can then execute one or more methods for other clients. When this command is executed, a process, named clientName, is created on the client station. This process can only be aborted by the UNREGISTER CLIENT command. If you pass the optional * parameter, the created process is local. 4D will automatically add the dollar sign ($) at the beginning of the process name. Else, the process is global. After executing the command, the client station will periodically ask 4D Server to see if another 4D Client or the server itself is calling it. By default, this interrogation is done every two seconds. You can modify this time period by modifying period. The minimum value is one second.

Note: If this command is used with a single-user version of 4th Dimension, it has no effect.

Once the command is executed, it is not possible to modify 4D Client's name or the server's interrogation period on the fly. To do so, you must call the UNREGISTER CLIENT command, then the REGISTER CLIENT command.

Note: More than one 4D Client can have the same registered name.

If 4D Client is correctly registered, the OK system variable is equal to 1. If 4D Client was already registered, the command doesn't do anything and OK is equal to 0.

In the following example, we are going to create a small messaging system that allows the client workstations to communicate between themselves:

1) This method, Registration, allows you to register a 4D Client and to keep it ready to receive a message from another 4D Client:

`You must unregister before registering under another name
UNREGISTER CLIENT
Repeat
vPseudoName:=Request("Enter your name:";"User";"OK";"Cancel")
Until ((OK=0) | (vPseudoName # ""))
If (OK=0)
...` Don't do anything
Else
REGISTER CLIENT(vPseudoName)
End if

2) The following instruction allows you to get a list of the registered 4D Clients. It can be placed in the On Startup database method:

PrClientList:=New process("4D Client List";32000;"List of registered clients")

3) The method 4D Client List allows you to recuperate all the registered 4D Clients and those that can receive messages:

If (Application type=4D Client)
` the code below is only valid in client-server mode
$Ref:=Open window(100;100;300;400;-(Palette window+Has window title);"List of registered clients")
Repeat
GET REGISTERED CLIENTS($ClientList;$ListeCharge)
`Retrieve the registered clients in $ClientList
ERASE WINDOW($Ref)
GOTO XY(0;0)
For ($p;1;Size of array($ClientList))
MESSAGE($ClientList{$p}+Char(Carriage return))
End for
`Display each second
DELAY PROCES(Current process;60)
Until (False) ` Infinite loop
End if

4) The following method allows you to send a message to another registered 4D Client. It calls the Display_Message method (see below).

$Addressee:=Request("Addressee of the message:";"")
` Enter the name of the people visible in the window generated by the
` On Startup database method
If (OK # 0)
$Message:=Request("Message:") ` message
If (OK # 0)
EXECUTE ON CLIENT($Addressee;"Display_Message";$Message) ` Send message
End if
End if

5) Here is the Display_Message method:

C_TEXT($1)
ALERT($1)

6) Finally, this method allows a client station to no longer be visible by the other 4D Clients and to no longer receive messages:

UNREGISTER CLIENT