There are three disconnect options:
The first option is to stop the session. The following example demonstrates a simple connect and disconnect, stopping the session.
Option Explicit
Dim objCon As New HostConnection 'Connection object
Sub DisconnectStop()
objCon.HostName = "Insure" 'set to match the hostname settings in admin console
objCon.connect "standard"
Debug.Print "Connected." & vbCrLf
objCon.disconnect "stop"
Debug.Print "Session terminated!" & vbCrLf
End Sub
|
public class FSCProFunctions
{
private HostConnection con = new HostConnection();
private void DisconnectStop()
{
con.HostName = "Insure"; //set to match the hostname settings in admin console
con.connect("standard");
Debug.WriteLine("Connected.");
con.disconnect("stop");
Debug.WriteLine("Session terminated!");
}
}
|
The reserve option disconnects the HostConnection object from the session, but the session remains connected to the host. In order to reconnect to the session two criteria have to met:
1. | The HostConnection object attempting to reconnect to the session must be running in the same process as the object that created the session. |
2. | The HostConnection object reconnecting to the session must be provided with the SessionKey of the session to connect to. |
The following example demonstrates how the reserve option can be used.
Option Explicit
Dim objCon As New HostConnection 'Connection object
Dim objCon2 As New HostConnection 'Connection object
Dim strSessionKey As String 'SessionKey
Sub DisconnectReserve()
Dim strSessionKey As String
objCon.HostName = "Insure" 'set to match the hostname settings in admin console
objCon.connect "standard"
strSessionKey = objCon.sessionKey
Debug.Print "Connected." & vbCrLf
objCon.disconnect "reserve"
Debug.Print "Disconnected but session left open and locked." & vbCrLf
objCon2.sessionKey = strSessionKey
objCon2.connect
Debug.Print "Connected to the same session but on a different HostConnection object." & vbCrLf
objCon2.disconnect "stop"
Debug.Print "Session terminated!" & vbCrLf
End Sub
|
public class FSCProFunctions
{
private HostConnection con = new HostConnection();
private HostConnection con2 = new HostConnection();
private string sessionKey;
private void DisconnectReserve()
{
string strSessionKey;
con.hostName = "Insure"; //set to match the hostname settings in admin console
con.connect("standard");
sessionKey = con.sessionKey;
Debug.WriteLine("Connected.");
con.disconnect("reserve");
Debug.WriteLine("Disconnected but session left open and locked.");
con2.sessionKey = sessionKey;
con2.connect();
Debug.WriteLine("Connected to the same session but on a different HostConnection object.");
con2.disconnect("stop");
Debug.WriteLine("Session terminated!");
}
}
|
In this example two HostConnection objects are created. The first creates the session, stores the SessionKey, and then disconnects - reserving the session. The second HostConnection object uses the SessionKey to connect to the session, and then it disconnects - stopping the session.
The second HostConnection met the two criteria and so was able to reconnect to the session:
•It used the sessions SessionKey.
•It runs in the same process as the first HostConnection object.
Note that for a IIS web application if the session were reserved and the SessionKey value was passed to another ASP page (within the same web application), reconnection to the session would be possible, as both the ASP pages would run in the same IIS application process.
The final type of session handling is used return the session back to a pool (i.e. session pooling). If a HostConnection object were to create a new session and then disconnect with the release option, the session would remain connected. The next session to make a connection would be given the session that is already connected to the host.
The following example demonstrates the use of the release option in a disconnect.
Option Explicit
Dim objCon As New HostConnection 'Connection object
Dim objCon2 As New HostConnection 'Connection object
Sub DisconnectRelease()
objCon.HostName = "Insure" 'set to match the hostname settings in admin console
objCon.connect "standard"
If objCon.newSession Then
Debug.Print "This is the first time the session has been connected to." & vbCrLf
Debug.Print "Use the HostScreen object to log in." & vbCrLf
End If
Debug.Print "Connected." & vbCrLf
objCon.disconnect "release"
Debug.Print "Session released back into the pool. Note that it has not been terminated." & vbCrLf
objCon2.connect
If objCon2.newSession Then
Debug.Print "This is a new session." & vbCrLf
Debug.Print "Use the HostScreen object to log in." & vbCrLf
Else
Debug.Print "This session has been used previously and should already be logged in." & vbCrLf
End If
objCon2.disconnect "stop"
Debug.Print "Session terminated!" & vbCrLf
End Sub
|
public class FSCProFunctions
{
private HostConnection con = new HostConnection();
private HostConnection con2 = new HostConnection();
private void DisconnectRelease()
{
con.HostName = "Insure"; //set to match the hostname settings in admin console
con.connect("standard");
if(con.newSession)
{
Debug.WriteLine("This is the first time the session has been connected to.");
Debug.WriteLine("Use the HostScreen object to log in.");
}
Debug.WriteLine("Connected.");
con.disconnect("release");
Debug.WriteLine("Session released back into the pool. Note that it has not been terminated.");
con2.connect();
if(con2.newSession)
{
Debug.WriteLine("This is a new session.");
Debug.WriteLine("Use the HostScreen object to log in.");
}
else
{
Debug.WriteLine("This session has been used previously and should already be logged in.");
}
con2.disconnect("stop");
Debug.WriteLine("Session terminated!");
}
}
|
There are a quite a few things different in the code above to what has already been done. The standard connection is made, but then a HostScreen object is retrieved using the getScreen method. The HostScreen object is used to interact with the screen, and in this case to send some keystrokes and an action key (the enter key) to the screen. This should put the session on a new screen, which means that when the session is released it will not be on the starting screen.
The second HostConnection object connects in the standard manner, but take note that it does NOT use the SessionKey. In fact, the SessionKey is no longer valid. Once connected, the HostConnection object checks to see if the session has already been connected. If not, then it runs the same login sequence that was performed for the first HostConnection object.
What is important to understand here is that if the connection and login has already been performed then it will not have to be done again. This gives a great performance increase as the host connection and signon sequence is processor intensive and time-consuming.