Dynamic View Services > Implementing a Dynamic View Server and its Components > Connecting Components and Opening Views > Connection Control
 
Connection Control
On the server side, you can control which components connect to the server and when. A set of virtual methods is called both on IlsMvUser and IlsMvServer objects.
Connection
At connection time, the following actions are performed:
1. The server receives the connection request.
2. The server creates the corresponding IlsMvComponentItf object.
3. The server receives the component properties.
4. The server creates the corresponding IlsMvUser object.
5. If User Info has been passed using the virtual method IlsMvComponentFactory::getUserInfo on the component side, that information is assigned to the IlsMvUser object.
User Info denotes some extra information that can be provided by the component to characterize the connecting user (such as password, real name, and the like). This information is handled as follows:
*It is provided as a set of IlsMvValue objects through the component factory on the component side;
*Then, it is sent to the server during the connection phase;
*Then, it is stored in the IlsMvUser object.
User Info is not used by Rogue Wave® Server.
6. The function IlsMvUser::onBind is called.
7. The function IlsMvServer::acceptConnection is called.
8. If that method returns true, the function IlsMvServer::onConnect is called, the function IlsMvUser::onUnbind is called and the user is deleted.
Note: The function IlsMvServer::onDisconnect is not called in this case
Disconnection
When a component is disconnecting, the following actions are performed:
1. The function IlsMvUser::onUnbind is called.
2. The function IlsMvServer::onDisconnect is called.
3. The corresponding IlsMvComponentItf object is deleted.
4. The corresponding IlsMvUser object is deleted.
The Connection Protocol and MvTCP
This section draws your attention to some aspects of the connection protocol on the component side when you use the MvTCP communication layer.
When the component connects to the server, the following actions take place:
1. A query is sent to the Rogue Wave Server logical mapper to retrieve the TCP port number associated with the server to which the component is connected.
This query is sent through the method IlsTcpMvProcess::lookupProcess . This method can be overriden.
2. A synchronous call is sent to the server. This call may time out and the connection fails if the server is not responsive.
You can control the timeout using the method IlsTcpMvProcess::SetTcpTimeout.
3. A connection request is sent to the server. The server may accept it or refuse it.
4. In the meantime, the server opens a duplex connection to the client.
*If the server accepts the connection (which is the default behavior), acknowledgment is sent back to the component.
* If the connection is denied, the server sends a Connection Error message and closes the connection.
See the following member functions:
*IlsMvServer::acceptConnection
*IlsMvComponent::connectionDenied
*IlsMvComponent::connectionAllowed
You can trace all these steps of the connection protocol by setting the MvTCP trace mode (See Appendix E, The MvTCP Communication Layer for details).
You can handle the successive phases of the connection protocol by subclassing IlsMvComponent and overriding some of its member functions. The following actions take place during the connection of a component to a server:
1. The static member function IlsMvComponent::Connect is invoked.
2. An instance of the class IlsMvComponent or of a subclass is created through the component factory.
3. User info is requested through the component factory. See the method IlsMvComponentFactory::getUserInfo.
4. The virtual member function IlsMvComponent::onConnect is invoked.
5. The function IlsMvComponent::Connect returns.
6. When the main loop is invoked, the component receives three low-level messages from the server:
*the acceptance of the duplex connection initiated by the server;
*a bind reply to establish the duplex connection;
*a connection acknowledgement or connection denial if one of the methods IlsMvComponent::connectionAllowed or IlsMvComponent::connectionDenied is invoked.
The component application handles the reception of these messages by calling IlsMvProcess::Run. To make sure that the connection is well established (before using it, for instance), you may call IlsMvProcess::Run(3) just after the connection so as to receive the messages described in step 6.
Warning: Using the connection from the component before having handled the connection messages may lead to weird behavior, especially if the connection is unexpectedly broken by the server.
The parameter means that no more than three attempts at connection take place before the messages received from the server (described in step 6) are read. After this maximum number of pending connections is reached, the subsequent connection attempts are refused by the server.
Initialization
When the server is initialized, a default component associated with a default user is created. This default component is used as the component associated with linked views if no such component is specified (see IlsMvServer::OpenView). You can retrieve the default component using the static member function IlsMvServer::GetDefaultComp.
This default component is created just after IlsMvServer (or your subclass) is instantiated but before the command line options are parsed. Note that a default user is also created and the function onBind is called for this component. The function GetDefaultComp returns 0 until initialization of the default component is complete.
Note: When a connection is refused because no licenses are available on the server side, that connection is broken at a very early stage and standard callbacks (such as acceptConnection and onDisconnect) are not called. The connection attempt on the component side just fails.
When using the default component, you should also be aware that any method called through that component (such as openView, execCallback, and so on) or on its related representation object is executed synchronously by the current thread. As a consequence, the default component should only be manipulated by the main thread.

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.