High Performance Network Framework
- Server Based on IOCP/EPOLL communication model, combined with technology of memory pool, private heap etc., efficient memory management is implemented to support large scale and high concurrent communication scenarios.
- Agent The Agent component is essentially a Multi-Client component that uses the same technical architecture as the Server component. An Agent component object can create and efficiently handle large-scale Socket connections at the same time.
- Client Based on Event-Select/POLL communication model, each component object creates a communication thread and manages a Socket connection. Client components are suitable for small-scale client scenarios.
- HP-Socket Development Guide [pdf]
- HP-Socket Class Diagram [uml]
- HP-Socket Class Diagram [jpg]
- HP-Socket SSL Class Diagram [jpg]
- HP-Socket HTTP Class Diagram [jpg]
- Create listener object
- Create component object (and binding with listener object)
- Start component object
- Connect to dest host (for Agent Component only)
- process network events (OnConnect/OnReceive/OnClose etc.)
- Stop component object (optional: component object will be stopped before destroy in step 7)
- Destroy component object
- Destroy listener object
- C++ Example
#include<hpsocket/HPSocket.h>/* Listener Class */classCListenerImpl : publicCTcpPullServerListener
{
public:// 5. process network eventsvirtual EnHandleResult OnPrepareListen(ITcpServer* pSender, SOCKET soListen);
virtual EnHandleResult OnAccept(ITcpServer* pSender, CONNID dwConnID, UINT_PTR soClient);
virtual EnHandleResult OnHandShake(ITcpServer* pSender, CONNID dwConnID);
virtual EnHandleResult OnReceive(ITcpServer* pSender, CONNID dwConnID, int iLength);
virtual EnHandleResult OnSend(ITcpServer* pSender, CONNID dwConnID, constBYTE* pData, int iLength);
virtual EnHandleResult OnClose(ITcpServer* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode);
virtual EnHandleResult OnShutdown(ITcpServer* pSender);
};
intmain(int argc, char* const argv[])
{
// 1. Create listener object
CListenerImpl s_listener;
// 2. Create component object (and binding with listener object)
CTcpPullServerPtr s_pserver(&s_listener);
// 3. Start component objectif(!s_pserver->Start("0.0.0.0", 5555))
exit(1);
/* wait for exit */// ... ... // 6. (optional) Stop component object
s_pserver->Stop();
return0;
// 7. Destroy component object automatically// 8. Destroy listener object automatically
}- C Example
#include<hpsocket/HPSocket4C.h>// 5. process network eventsEnHandleResult__HP_CALLOnConnect(HP_AgentpSender, HP_CONNIDdwConnID);
EnHandleResult__HP_CALLOnReceive(HP_AgentpSender, HP_CONNIDdwConnID, intiLength);
EnHandleResult__HP_CALLOnSend(HP_AgentpSender, HP_CONNIDdwConnID, constBYTE*pData, intiLength);
EnHandleResult__HP_CALLOnClose(HP_AgentpSender, HP_CONNIDdwConnID, En_HP_SocketOperationenOperation, intiErrorCode);
EnHandleResult__HP_CALLOnShutdown(HP_AgentpSender);
intmain(intargc, char*constargv[])
{
HP_TcpPullAgentListeners_listener;
HP_TcpPullAgents_agent;
// 1. Create listener objects_listener= ::Create_HP_TcpPullAgentListener();
// 2. Create component object (and binding with listener object)s_agent= ::Create_HP_TcpPullAgent(s_listener);
/* Set listener callbacks */
::HP_Set_FN_Agent_OnConnect(s_listener, OnConnect);
::HP_Set_FN_Agent_OnSend(s_listener, OnSend);
::HP_Set_FN_Agent_OnPullReceive(s_listener, OnReceive);
::HP_Set_FN_Agent_OnClose(s_listener, OnClose);
::HP_Set_FN_Agent_OnShutdown(s_listener, OnShutdown);
// 3. Start component objectif(::HP_Agent_HasStarted(s_agent))
exit(1);
// 4. Connect to dest host
::HP_Agent_Connect(s_agent, "remote.host.1", REMOTE_PORT_1, nullptr);
::HP_Agent_Connect(s_agent, "remote.host.2", REMOTE_PORT_2, nullptr);
::HP_Agent_Connect(s_agent, "remote.host.3", REMOTE_PORT_3, nullptr);
/* wait for exit */// ... ... // 6. (optional) Stop component object
::HP_Agent_Stop(s_agent);
// 7. Destroy component object
::Destroy_HP_TcpPullAgent(s_agent);
// 8. Destroy listener object
::Destroy_HP_TcpPullAgentListener(s_listener);
return0;
}- Basic Components
- SSL Components
- HTTP Components



