Communication in Process Manager
It is important to keep in mind that when Process Manager tries to communicate, the application on the other side must be receptive to the commands and queries, and must respond appropriately. Altair products (HyperMesh/HyperWorks) have the necessary hooks to understand the protocols of communication with Process Manager. When it is required for Process Manager to spawn and establish a communication socket with a third party application (Unigraphics, for example), it will be necessary to write a ufunc dll (on the Unigraphics side in this case). The ufunc dll will connect to the server socket created by Process Manager, listen to the socket for instruction, and act appropriately. When writing these dlls, it is important to understand the underlying protocol for such communications.
Protocol for Communication
- When spawning an application
-
- HWMCommMgr creates a server socket.
HWMCommMgr appends the following two arguments to the command line arguments:
- xcommport=<server port number>
- xcommid=<the session name>
- HWMCommMgr spawns the external application and waits for the application to connect to the server socket.
- HWMCommMgr expects the application to pass the session name through the socket and back to it in order to confirm that the application connecting is the one that is expected.
- When sending a message
- HWMClientComm prepends the letter C to the command before sending it
through the socket. For example:
commHM.SendCommand("*readfile D:/altair/demos/hm/bumper.hm")
"C *readfile D:/altair/demos/hm/bumper.hm"
is the actual string sent through the socket.HWMClientComm prepends the letter Q to any query before sending it through the socket.
- When receiving a response
- HWMClinetComm expects the response through the socket in the following
format:
"1 My name is Jay" or "0 I did not understand the query"
If the response starts with "1", it implies that the query was executed successfully, the information following the 1 is interpreted as the actual response.
If the response starts with "0", it implies that the query was not executed successfully, and the information following is interpreted as the failure message.
The application can send an instruction to Process Manager on its own, but such instructions should not start with "1" or "0." The HWMClientComm will fire an event (HWMCommEvent) to all beans that have added themselves as HWMCommEventListener.
- Connecting to Applications
-
public void DoSomething() HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr(); HWMClientComm hwmComm = hwmCommMgr.ConnectToApp(strAddress, // The server address nPort, //The port number "MY_SESSION" /*The session name*/ ); HWMResponseHandle response = hwmComm.SendQuery("..."); . . . }
HyperMesh/HyperWorks working in server mode:
public void DoSomething() HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr(); HWMCommHM commHM = hwmCommMgr.ConnectToHM(strAddress, //The server address nPort, //The port number "MY_SESSION" /*The session name*/ ); HWMResponseHandle response = commHM.SendQuery("..."); . . . }
- Connecting to a database server
-
public void DoSomething() HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr(); DBServerComm dbComm = hwmCommMgr. StartDBComm( "MY_DBSESSION" /*The session name*/ ); dbComm.Connect(HWMDatabaseInfo.DBTYPE_MYSQL, //DB TYPE strAddress, nPort, //Address & port that the DB //server is listening to strDBName, //The database name strUser, strPwd, //User and password bCreate /*Create DB if it does not exist*/); }
As shown in the example above, the CommMgr has a method called StartDBComm, which returns an instance of DBServerComm. The instance of DBServerComm can be used to connect to a database. The DBServerComm class implements the connection interface, and for all purposes, the StartDBComm method has returned an instance of Connection. Appropriate methods in the DBServerComm class will allow you to:
- Create Statements
- Prepare Statements
- Prepare Calls
- Set Auto Commits
- Commit