Connecting to a duplicated operation server

<< Click to Display Table of Contents >>

Manual > Server Creation Guide > Interface > IPLink-Interface > IPLinkClient Library > IPLinkClient Library Sample Collection >

Connecting to a duplicated operation server

overview

This is a sample program that connects to a running Server application when the Server application is operated in duplicate. In this sample, if the connection to the IPLink server is lost, the connection will be automatically made to another IPLink server. This allows the Server application to be operated in duplicate.

 

Normally, IPLink can only be set to one IPLink server. Therefore, when the connection status becomes disconnected, it is designed to automatically connect to the second IPLink server registered.

 

c_interface_0143

 

 

Download the sample

The creation examples shown on this page are provided with samples.

 

The sample can be downloaded from below.

 

Samples and detailed explanations will be provided in VB.NET2010.

 

 

hint

In this sample, the main machine's IP address is 192.168.1.1, and the sub machine's IP address is 192.168.1.2. When actually performing operations, change the IP addresses to suit your environment.

 

 

Server Configuration

1.Make sure IPLink-Interface is enabled. Also, set the main and sub IP addresses.
 
In this sample, the IP address is set using an environment variable. Click the variable button to the right of the IP address to display the setting screen.
 
c_interface_0144
 

2.When the Environment Variables screen appears, click the Add button.
 
c_interface_0145
 

3.Configure the settings as follows:
 
c_interface_0146
 
Variable name: [IP]
Main machine value: 192.168.1.1
Check Enable Duplication
Main machine value: 192.168.1.2
 

4.Click the OK button to close the dialog, select the environment variable you added, and click the OK button.
 
c_interface_0147
 

5.Verify that the environment variable is set in the IP address item, then click OK to close the dialog.
 
c_interface_0148
 

6.Next, configure the duplex interface.
 
Open the properties of the Redundancy interface and set the IP address and port number for the main and sub interfaces.
After completing the settings, close the dialog by clicking the OK button.
 
c_interface_0149
 

7.Set whether the server will operate as the main or sub server.
 
This setting must be done on both the main and sub machines. Open "Operation" - "Options" - "Startup Settings" and make the setting.
 
c_interface_0150
 
If it's your main machine, select "Start your machine as the main machine"
For a sub-machine, "Start your machine as a sub-machine"
 
This setting will take effect after restarting the Server application, so please restart the Server application.

 

 

hint

Normally, the IP addresses of the main and sub machines are different, so it is necessary to set the interface to an IP that matches each environment. In that case, multiple configuration files for the server application are required, and it becomes necessary to manage multiple configuration files. To avoid this, use the environment variable function. By using this function, it becomes possible to operate with a single configuration file in both the main and sub machine environments.

 

 

Program Highlights

We will explain the main points of the program.

 

Connection Handling
When the Connect button is pressed, the NetworkParam properties are set and initial settings such as AddTag are performed. In addition to the normal tags, AddTag also includes "//Redundancy/StateMain" and ""//Redundancy/StateSub"". These two are called system properties, and are properties that can obtain the status of the Server application during redundant operation.
 
To get the value of a system property, you need to AddTag it just like a regular tag, so you will do this in this process.
 

'Connect Parameter set
fvNetworkParam1 = txtMainParam.Text
fvNetworkParam2 = txtSubParam.Text

For i = 0 To fcItemCount + 1
    If i < 1 Then
        fvTagName(i) = fvTargetTag01
    Else
        fvTagName(i) = fvSystemTags(i - 1)
    End If
    fvActives(i) = True
Next i

AxIPLink1.AddTags(fcItemCount + 2, fvTagName, fvActives, vResults)
AxIPLink1.NetworkParam = fvNetworkParam1
AxIPLink1.Online = True
AxIPLink1.CtlUpdate = True

 

 

hint

The following information can be obtained from the system properties:

 

"//Redundancy/StateMain": Indicates the status of the main unit (1: Abnormal/2: Standby/3: Operating)

"//Redundancy/StateSub": Shows the status of the sub unit (1: Abnormal/2: Standby/3: In operation)

 

 

Get the duplication status of the Server application
The value of the redundant system property is obtained by the ValueStateChanged event and displayed in a text box. This allows you to check the status of both the main and sub machines on the screen.
 

'------------------------------------------
' Event - ValueStateChanged
'------------------------------------------
Private Sub AxIPLink1_ValueStateChanged(sender As Object, e As AxIPLINKLib6._DClientIPLinkEvents_ValueStateChangedEvent) Handles AxIPLink1.ValueStateChanged

    '/// Redundancy Status //////////////////////////////////////
    If fvSystemTags(0) = e.tagPath Or fvSystemTags(1) = e.tagPath Then
        '/// Redundancy Status(Main Machine Status) //////////////////////////////////////
        If fvSystemTags(0) = e.tagPath Then
            If e.value Is CStr(1) Then
                lblMainState.Text = fvStatus(0)
            ElseIf e.value Is CStr(2) Then
                lblMainState.Text = fvStatus(1)
            ElseIf e.value Is CStr(3) Then
                lblMainState.Text = fvStatus(2)
            Else
                lblMainState.Text = fvStatus(3)
            End If
        End If
        '/// Redundancy Status(Sub Machine Status) //////////////////////////////////////
        If (fvSystemTags(1) = e.tagPath) Then
            If e.value Is CStr(1) Then
                lblSubState.Text = fvStatus(0)
            ElseIf e.value Is CStr(2) Then
                lblSubState.Text = fvStatus(1)
            ElseIf e.value Is CStr(3) Then
                lblSubState.Text = fvStatus(2)
            Else
                lblSubState.Text = fvStatus(3)
            End If
        End If
    End If
End Sube

 
 

Get the duplication status of the Server application
The value of the redundant system property is obtained by the ValueStateChanged event and displayed in a text box. This allows you to check the status of both the main and sub machines on the screen.
 

'------------------------------------------
' Event - StateChanged
'------------------------------------------
Private Sub AxIPLink1_StateChanged(sender As Object, e As AxIPLINKLib6._DClientIPLinkEvents_StateChangedEvent) Handles AxIPLink1.StateChanged
    '/// IPLink Status ///////////////////////////////////////////
    lblIPLinkState.Text = CStr(e.state)

    '/// Redundancy Status Change ////////////////////////////////
    If e.state = True Then
        Timer1.Enabled = False
    Else
        Timer1.Interval = fcTimerInterval
        Timer1.Enabled = True
    End If
End Sub

 

 

hint

In this sample, if there is a change in the connection state, a timer is used to set an interval and switch the connection. This is to prevent frequent switching processes when a connection cannot be established to both the main and sub. The interval is set by the variable "fvTimerInterval" and you can change the connection interval by changing this value.

 

 

Operation check

1.After bringing the main application and then the sub application online, display the information of the Redundancy interface of the main application and confirm that both "State" and "Line1 State" are "Running".
 
Also, at this time, the machine that comes online last will go into waiting state, so the "State" on the sub machine will become "Waiting".
 
c_interface_0151 c_interface_0152
 

2.Run your Visual or Basic application and verify that the Main State is "Running" and the Sub State is "Waiting".
 
Also, please confirm that you can obtain the tag value by pressing the Read button.
 
c_interface_0153

 

3.If the main machine is running and the sub machine is offline, please make sure that Sub State becomes Abnormal.
 
Also, if the main machine is offline while the sub machine is running, make sure that Main State becomes Abnormal.
 
c_interface_0154  c_interface_0155