Using MvTCP in Server Applications

In C++, use the class IlsTcpMvProcess to initialize the server and the component:

#include <ilserver/mvtcp/tcpmvproc.h>

...

int main(argc, argv)

{

if (!IlsTcpMvProcess::Initialize(argc, argv)) {

IlsError() << "Failed to initialize communication layer" << IlsEOM;

}

...

IlsMvProcess::Run();

}

You can specify to which TCP port the process should listen for incoming connection requests by specifying a value for the last argument to the Initialize function. By default, MvTCP selects the first available port.

If you use this communication layer with Views, use the class IlsIlvTcpMvProcess. This class features an integration of the MvTCP main loop with the Views main loop.

#include <ilserver/mvtcp/tcpvmvproc.h>

...

int main(argc, argv)

{

if (!IlsIlvTcpMvProcess::Initialize(argc, argv)) {

IlsError() << "Failed to initialize communication layer" << IlsEOM;

}

...

IlvMainLoop();

}

Its implementation differs slightly on UNIX® platforms and Windows® platforms.

  • On UNIX platforms, MvTCP registers its file descriptors with the Views files that are polled by the Views main loop. Views calls back a specific function when an event is detected in one of these file descriptors.

  • On Microsoft Windows platforms, MvTCP launches a separate thread which listens to the MvTCP file descriptor through a select system call. MvTCP also creates a hidden window with a specific Windows Proc. When an event is detected in a file descriptor, the listening thread creates a Windows Message and sends it to the standard Windows main message loop. The dispatching mechanism of the Windows message loop forwards this message to the MvTCP-specific Windows Proc which reads the file descriptors and processes the incoming requests.

As a result, this integration works with any graphical product that uses the standard Windows message loop.

In a JavaTM component, use the ilog.server.mvtcp.MvProcess class to initialize the component, like this:

import ilog.server.mvtcp;

 

static void main() {

MvProcess.Initialize();

}