For three years, three years, three years again, finally, finally, don't have to wait at last! Just for today, HP - Socket for Linux v1.0 release!! Is still the same interface, as well as efficient, easy, the same taste,
HP - Socket for Linux provides consistent with Windows API interface, the implementation code is completely independent, HP - Socket for Linux using the new characteristic of the 14 c + + standard, need GCC 5. X the above version of the compiler to compile and publish a package of offers HP - Socket components and sample Demo Visual Studio project engineering, installation configuration for Linux Development with a good Visual Studio Visual c + + plugin compiled by oneself, after, of course, you can also write your own Makefile to compile the code,
Note: the HP - Socket for Linux to compile and run the need 2.6.32 and above version of the Linux kernel,
The categories of HP - Socket components, details please refer to the "HP - Socket network communication framework development guide" :
Server: communication model based on IOCP/EPOLL, and connecting with the buffer pool, private heap, and other technology to achieve efficient memory management, support for very large scale, high concurrency communication scenarios,
Agent: the Agent component is essentially Multi - Client component, and Server components using the same technology architecture, an Agent component object can establish and efficient processing large-scale Socket connection at the same time,
Client: communication model based on Event the Select/POLL, each component object to create a thread communication and manage a Socket connection, is suitable for the small-scale Client scenario,
* HP - Socket's official website: http://www.jessma.org
* HP - Socket project home page: https://github.com/ldcsaa/HP-Socket
* HP - Socket development documentation: http://www.oschina.net/p/hp-socket/doc
installation guide
$sudo./install. Sh -h
Usage: install. Sh O.P.T.I.O.N.S... [...]
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- p | -- prefix: install/uninstall the path (default:/usr/local)
- l | - libdir: lib dir (default: x86 - & gt; Lib, x64 - & gt; Lib64)
- d | - with - demo: install demos or not (default: true)
-u | - uninstall: execute uninstall operation from the install path
- v | - version: print installing HP - socket version
- h | -- help: print this usage message
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1. Create a listener object
2. Create a component object (and bind the listener)
3. Start the component
4. Connect to the remote host (only for Agent components)
5. Deal with communication event (OnConnect/OnReceive/OnClose... )
6. Stop components (optional, step 7 stop before destruction of component object components)
7. Destroy the component object
8. Destroy the listener object
* c + + example
# include & lt; Hpsocket/hpsocket. H>* C example
/* Listener Class */
The class CListenerImpl: public CTcpPullServerListener
{
Public:
//5. The process network events
Virtual 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, const BYTE * pData, int iLength);
Virtual EnHandleResult OnClose (ITcpServer * pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode);
Virtual EnHandleResult OnShutdown (ITcpServer * pSender);
};
Int main (int arg c, char * const argv [])
{
//1. Create a listener object
CListenerImpl s_listener;
//2. The Create component object (and binding with the listener object)
CTcpPullServerPtr s_pserver (& amp; S_listener);
//3. Start component object
if(! S_pserver - & gt; Start (" 0.0.0.0 ", 5555))
The exit (1);
/* wait for the exit */
//... .
//6. (optional) the Stop component object
S_pserver - & gt; Stop ()
return 0;
//7. Destroy component object automatically
//8. Destroy the listener object automatically
}
# include & lt; Hpsocket/HPSocket4C. H>
//5. The process network events
EnHandleResult __stdcall OnConnect (HP_Agent pSender, HP_CONNID dwConnID);
EnHandleResult __stdcall OnReceive (HP_Agent pSender, HP_CONNID dwConnID, int iLength);
EnHandleResult __stdcall OnSend (HP_Agent pSender, HP_CONNID dwConnID, const BYTE * pData, int iLength);
EnHandleResult __stdcall OnClose (HP_Agent pSender, HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode);
EnHandleResult __stdcall OnShutdown (HP_Agent pSender);
Int main (int arg c, char * const argv [])
{
HP_TcpPullAgentListener s_listener;
HP_TcpPullAgent s_agent;
//1. Create a listener object
S_listener=: : Create_HP_TcpPullAgentListener ();
//2. The Create component object (and binding with the listener object)
S_agent=: : Create_HP_TcpPullAgent (s_listener);
/* Set the 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 object
If (: : HP_Agent_HasStarted (s_agent))
The exit (1); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull