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
// interface
ILMNetProtocolManager* 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 point
hRes = 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 code
if (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 needed
CoTaskMemFree(strPeer);
// The server is now ready to send the data
pBuff = (BYTE*)malloc(1024);
dSize = 1024;
ILMNetConnection_Send(pServerCon, pBuff, dSize, &dSize, 1000);
// If there is any blocking call, call the CancelBlockingCall method
ILMNetConnection_CancelBlockingCall(pServerCon);
// To disconnect, call the Disconnect method
ILMNetConnection_Disconnect(pServerCon);
// Close the connection point
ILMNetConnectionPoint_Close(pConnection);
// Free the pointers
free(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
// interface
ILMNetProtocolManager* pProtocol;
HRESULT hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pProtocol);
if (FAILED(hRes))
return;
// Create the server connection point
ILMNetConnectionPoint *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 code
if (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 needed
CoTaskMemFree(strPeer);
// The server is now ready to send the data
BYTE *pBuff = new BYTE[1024];
DWORD dSize = 1024;
pServerCon->Send(pBuff, dSize, &dSize, 1000);
// If there is any blocking call, call the CancelBlockingCall method
pServerCon->CancelBlockingCall();
// To disconnect, call the Disconnect method
pServerCon->Disconnect();
// Close the connection point
pConnection->Close();
// Free the pointers
delete[] 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
// interface
hRes = CoCreateInstance(&CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, &IID_ILMNetProtocolManager, (void**)&pProtocol);
if (FAILED(hRes))
return;
// Connect to the server
hRes = 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 code
if (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 needed
CoTaskMemFree(strPeer);
// The client is now ready to receive the data
pBuff = (BYTE*)malloc(1024);
dSize = 1024;
ILMNetConnection_Recv(pClientCon, pBuff, dSize, &dSize, 1000);
// If there is any blocking call, call the CancelBlockingCall method
ILMNetConnection_CancelBlockingCall(pClientCon);
// To disconnect, call the Disconnect method
ILMNetConnection_Disconnect(pClientCon);
// Free the pointers
free(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
// interface
ILMNetProtocolManager* pProtocol;
HRESULT hRes = CoCreateInstance(CLSID_LMNetProtocolManager, NULL, CLSCTX_ALL, IID_ILMNetProtocolManager, (void**)&pProtocol);
if (FAILED(hRes))
return;
// Connect to the server
ILMNetConnection* 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 code
if (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 needed
CoTaskMemFree(strPeer);
// The client is now ready to receive the data
BYTE *pBuff = new BYTE[1024];
DWORD dSize = 1024;
pClientCon->Recv(pBuff, dSize, &dSize, 1000);
// If there is any blocking call, call the CancelBlockingCall method
pClientCon->CancelBlockingCall();
// To disconnect, call the Disconnect method
pClientCon->Disconnect();
// Free the pointers
delete[] 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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.