The following example demonstrates how to network (client and server) using a user-defined protocol. For an example of how to create a user-defined protocol, refer to How to Create a User-Defined Protocol.
// To use the network protocol manager interface, use the following code// Note that the protocol manager interface will use the protocol// interfaceILMNetProtocolManager* pProtocol;ILMNetConnectionPoint *pConnection = NULL;ILMNetConnection* pServerCon = NULL;BSTR strPeer;BYTE *pBuff = NULL;DWORD dSize;HRESULT hRes = CoCreateInstance(&CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, &IID_ILMNetProtocolManager, (void**)&pProtocol);if (FAILED(hRes))return;// Create the server connection pointhRes = ILMNetProtocol_CreateConnectionPoint(pProtocol, L"myschema://10.0.4.2:27015", &pConnection);if (FAILED(hRes)){ILMNetProtocol_Release(pProtocol);return;}// Wait for the new incoming connection.do{ILMNetConnectionPoint_GetConnection(pConnection, &pServerCon, 1000);Sleep(100);} while (pServerCon == NULL);// To check whether there is a connection, use the following codeif (ILMNetConnection_IsConnected(pServerCon) != S_OK){ILMNetConnection_Release(pServerCon);ILMNetProtocol_Release(pProtocol);return;}// Get the peer name (Client Name)ILMNetConnection_GetPeerName(pServerCon, &strPeer);// Free the string when no longer neededCoTaskMemFree(strPeer);// The server is now ready to send the datapBuff = (BYTE*)malloc(1024);dSize = 1024;ILMNetConnection_Send(pServerCon, pBuff, dSize, &dSize, 1000);// If there is any blocking call, call the CancelBlockingCall methodILMNetConnection_CancelBlockingCall(pServerCon);// To disconnect, call the Disconnect methodILMNetConnection_Disconnect(pServerCon);// Close the connection pointILMNetConnectionPoint_Close(pConnection);// Free the pointersfree(pBuff);ILMNetConnection_Release(pServerCon);ILMNetProtocol_Release(pProtocol);
// To use the network protocol manager interface, use the following code// Note that the protocol manager interface will use the protocol// interfaceILMNetProtocolManager* pProtocol;HRESULT hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pProtocol);if (FAILED(hRes))return;// Create the server connection pointILMNetConnectionPoint *pConnection = NULL;hRes = pProtocol->CreateConnectionPoint(L"myschema://10.0.4.2:27015", &pConnection);if (FAILED(hRes)){pProtocol->Release();return;}// Wait for the new incoming connection.ILMNetConnection* pServerCon = NULL;do{pConnection->GetConnection(&pServerCon, 1000);Sleep(100);} while (pServerCon == NULL);// To check whether there is a connection, use the following codeif (pServerCon->IsConnected() != S_OK){pServerCon->Release();pProtocol->Release();return;}// Get the peer name (Client Name)BSTR strPeer;pServerCon->GetPeerName(&strPeer);// Free the string when no longer neededCoTaskMemFree(strPeer);// The server is now ready to send the dataBYTE *pBuff = new BYTE[1024];DWORD dSize = 1024;pServerCon->Send(pBuff, dSize, &dSize, 1000);// If there is any blocking call, call the CancelBlockingCall methodpServerCon->CancelBlockingCall();// To disconnect, call the Disconnect methodpServerCon->Disconnect();// Close the connection pointpConnection->Close();// Free the pointersdelete[] pBuff;pServerCon->Release();pProtocol->Release();
ILMNetProtocolManager* pProtocol;ILMNetConnection* pClientCon;BSTR strPeer;BYTE *pBuff;DWORD dSize;HRESULT hRes;// To use the network protocol manager interface, use the following code// Note that the protocol manager interface will use the protocol// interfacehRes = CoCreateInstance(&CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, &IID_ILMNetProtocolManager, (void**)&pProtocol);if (FAILED(hRes))return;// Connect to the serverhRes = ILMNetProtocol_Connect(pProtocol, L"myschema://10.0.4.2:27015", &pClientCon, 1000);if (FAILED(hRes)){ILMNetProtocol_Release(pProtocol);return;}// To check whether there is a connection, use the following codeif (ILMNetConnection_IsConnected(pClientCon) != S_OK){ILMNetConnection_Release(pClientCon);ILMNetProtocol_Release(pProtocol);return;}// Get the peer name (Server Name)ILMNetConnection_GetPeerName(pClientCon, &strPeer);// Free the string when no longer neededCoTaskMemFree(strPeer);// The client is now ready to receive the datapBuff = (BYTE*)malloc(1024);dSize = 1024;ILMNetConnection_Recv(pClientCon, pBuff, dSize, &dSize, 1000);// If there is any blocking call, call the CancelBlockingCall methodILMNetConnection_CancelBlockingCall(pClientCon);// To disconnect, call the Disconnect methodILMNetConnection_Disconnect(pClientCon);// Free the pointersfree(pBuff);ILMNetConnection_Release(pClientCon);ILMNetProtocol_Release(pProtocol);
// To use the network protocol manager interface, use the following code// Note that the protocol manager interface will use the protocol// interfaceILMNetProtocolManager* pProtocol;HRESULT hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pProtocol);if (FAILED(hRes))return;// Connect to the serverILMNetConnection* pClientCon;hRes = pProtocol->Connect(L"myschema://10.0.4.2:27015", &pClientCon, 1000);if (FAILED(hRes)){pProtocol->Release();return;}// To check whether there is a connection, use the following codeif (pClientCon->IsConnected() != S_OK){pClientCon->Release();pProtocol->Release();return;}// Get the peer name (Server Name)BSTR strPeer;pClientCon->GetPeerName(&strPeer);// Free the string when no longer neededCoTaskMemFree(strPeer);// The client is now ready to receive the dataBYTE *pBuff = new BYTE[1024];DWORD dSize = 1024;pClientCon->Recv(pBuff, dSize, &dSize, 1000);// If there is any blocking call, call the CancelBlockingCall methodpClientCon->CancelBlockingCall();// To disconnect, call the Disconnect methodpClientCon->Disconnect();// Free the pointersdelete[] pBuff;pClientCon->Release();pProtocol->Release();
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
