How to Create a User-Defined Protocol

The user can create a user-defined protocol.

To create a user-defined protocol, you must create a COM Object that is a free threaded component which implements three interfaces (ILMNetProtocol, ILMNetConnection and ILMNetConnectionPoint ) for each supported user-defined protocol.

To create a user-defined protocol, perform the following steps:

  1. Create a new network protocol class that implements the ILMNetProtocol interface (e.g. CMyNetProtocol). The ILMNetProtocol interface contains both the client and the server methods. - To create client side behavior:
    1. Create a new class (e.g. CMyNetConnection) that inherits from the ILMNetConnection interface.
    2. Add a new helper method ConnectToServer to the CMyNetConnection class. This method will be called to make a connection to the server. It will receive the server URL as an input parameter.
    3. To provide client functionality, you need to override the Connect method In CMyNetProtocol class. Typically, the Connect method is responsible for:

a) Creating an instance of your implementation of the ILMNetConnection interface (CMyNetConnection).
b) Making a call to the ConnectToServer method from the newly created CMyNetConnection object, and sending it the URL as an input parameter. ConnectToServer will format and parse the URL that represents the server address that the client will connect to then open a physical network connection to create a network connection reference (e.g. Socket). The created connection reference will be used later to receive the data from the server.
c) Returning the created CMyNetConnection object reference to the caller method using the corresponding output parameter. The returned ILMNetConnection object will be used to receive data. - To create server side behavior:
1. Create a new class (e.g. CMyNetConnectionPoint) that inherits from the ILMNetConnectionPoint interface. An instance of connection point class will provide the server listening and client request retrieval (through ILMNetConnection) capabilities.
2. Add a new helper method Listen to the CMyNetConnectionPoint class. This method will be used to start listening to client incoming connection requests. This method will receive the local server address URL as an input parameter.
3. To provide server functionality, you need to override the CreateConnectionPoint method in the CMyNetProtocol class. Typically, the CreateConnectionPoint method is responsible for:

You can use the following source to register your user-defined protocol object.

To register your user-defined protocol, you need to pass your protocol name (e.g. myschema). To use your protocol, your URL should contains your protocol name (e.g. myschema:\\10.0.4.2: 27015,XXXX)

C Source

ILMNetProtocolManager* pManager; 
hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pManager); 
if (FAILED(hRes)) 
   return hRes; 
hRes = ILMNetProtocolManager_RegisterProtocol(pManager, L"myschema", CLSID_MyProtocol); 
if (FAILED(hRes)) 
{ 
   ILMNetProtocolManager_Release(pManager); 
   return hRes; 
} 
ILMNetProtocolManager_Release(pManager); 

C++ Source<

ILMNetProtocolManager* pManager; 
hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pManager); 
if (FAILED(hRes)) 
   return hRes; 
hRes = pManager->RegisterProtocol(L"myschema", CLSID_MyProtocol); 
if (FAILED(hRes)) 
{ 
   pManager->Release(); 
   return hRes; 
} 
pManager->Release(); 

5. Now, the protocol is ready to be used.
6. When the newly created protocol is no longer needed, unregister and release it.
You can use the following source to un-register and release your user-defined protocol object.

C Source

ILMNetProtocolManager* pManager; 
hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pManager); 
if (FAILED(hRes)) 
   return hRes; 
hRes = ILMNetProtocolManager_UnregisterProtocol(pManager, L"myschema"); 
if (FAILED(hRes)) 
{ 
   ILMNetProtocolManager_Release(pManager); 
   return hRes; 
} 
ILMNetProtocolManager_Release(pManager); 

C++ Source

ILMNetProtocolManager* pManager; 
hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pManager); 
if (FAILED(hRes)) 
   return hRes; 
hRes = pManager->UnregisterProtocol(L"myschema"); 
if (FAILED(hRes)) 
{ 
   pManager->Release(); 
   return hRes; 
} 
pManager->Release(); 

Help Version 21.0.2021.7.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Multimedia C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.