首页 > 代码库 > HP-Socket v3.2.2
HP-Socket v3.2.2
==========================================================================================
v3.2.2 upgrade :
==========================================================================================
> Increase some methods for helps:
-----------------
- Batch sending methods: SendPackets()
1) IClient / IServer / IAgent add the sending methods: SendPackets(dwConnID, pBuffers[], iBufferCount)
2) For TCP component - send all packets in order
3) For UDP component - make all the packets combined into one packet and send (the length of the packet can not be greater than the maxinum of length of a UDP packet which is set up) - small files sending methods: SendSmallFile()
1) ITcpClient / ITcpServer / ITcpAgent add the small files sending methods: SendSmallFile(dwConnID, lpszFileName, pHead, pTail)
2) By the parameters: pHead and pTail,each can add some definitions int the files heads and tails
3) SendSmallFile() only send the files whose size small than 4096 KB - HPSocket.dll and HPSocket4C.dll add following export methods:
1) SYS_WSAGetLastError():call the system‘s WSAGetLastError()
2) SYS_SetSocketOption():call the system‘s setsockopt()
3) SYS_GetSocketOption():call the system‘s getsockopt()
4) SYS_IoctlSocket() :call the system‘s ioctlsocket()
5) SYS_WSAIoctl() :call the system‘s WSAIoctl()
> update instructions:
-----------------
- HP-Socket v3.2.1 or previous versions for applications can upgrade to HP-Socket v3.2.2 safely
==========================================================================================
v3.2.1 upgrade:
==========================================================================================
> add communication components TcpAgent / TcpPullAgent :
-----------------
- for the proxy server and transit server etc. , server can be the client and launche a large-scale service connections to other servers.
- TcpClient / TcpPullClient basic on Event Select communication model,every component object manages one Socket and open a thread ,but the above scenario is not suitable.
- TcpAgent / TcpPullAgent basic on IOCP communication model,one componet object manages many Sockets,for the clients communication components of the proxy server and transit server.
- TcpAgent / TcpPullAgent methods are easy to use and provide following interface methods:
1) notice interface methods:
OnPrepareConnect(CONNID dwConnID, SOCKET socket)
OnConnect(CONNID dwConnID)
OnSend(CONNID dwConnID, const BYTE* pData, int iLength)
OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) //(Push model)
OnReceive(CONNID dwConnID, int iLength) //(Pull model)
OnClose(CONNID dwConnID)
one rror(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
OnAgentShutdown()
2) main operating methods:
Start(LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE)
Stop()
Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr)
Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0)
Disconnect(CONNID dwConnID, BOOL bForce = TRUE)
Fetch(CONNID dwConnID, BYTE* pData, int iLength) //(Pull model) - add TcpAgent / TcpPullAgent excemples for user:
1) Agent-PFM
2) Agent-Pull
3) Agent-4C - add TcpAgent + TcpServer HTTP proxy server excemple:HttpProxy
> add HPSocket for Java SDK:
-----------------
- provide Java development package:hpsocket-3.2.1.jar(by JNA ,now only supports Windows platform)
- running environment:JDK 1.6+,JVM runs server mode("java -server",in client mode,the properties affected)
- add the project TestEcho-4J,show the HPSocket4J using methods (includes Pull model examples and sample performance tests)
- MBCS and Unicode version are in the jars: org.jessma.hpsocket.mbcs and org.jessma.hpsocket.unicode
- HPSocket for Java SDK provides following communication components :
1) TcpServer:TCP communication server component ,supports PUSH/Pull model
2) TcpClient:TCP communication client component ,supports PUSH/Pull model
3) TcpAgent :TCP communication Agent component ,supports PUSH/Pull model
4) UdpServer:UDP communication server component ,supports Push model
5) UdpClient:UDP communication client component ,supports Push model - HPSocket4J using methods (using TcpAgent for example):
/* 0: add the jars into the project: hpsocket-3.2.1.jar and jna-4.1.0.jar */
/* 1: create communication component object */
TcpAgent agent = TcpAgent.create(Mode.PUSH);
/* 2: set the callback function object */
// (optional )
agent.setCallBackOnPrepareConnect(new OnPrepareConnectImpl());
// (optional )
agent.setCallBackOnConnect(new OnConnectImpl());
// (required )Push model need to set OnReceive callback function object
agent.setCallBackOnReceive(new OnReceiveImpl());
// (required )Pull model need to set OnPullReceive callback function object
// agent.setCallBackOnPullReceive(new OnPullReceiveImpl());
// (optional )
agent.setCallBackOnSend(new OnSendImpl());
// (required )
agent.setCallBackOnClose(new OnCloseImpl());
// (required )
agent.setCallBackOnError(new one rrorImpl());
// (optional )
agent.setCallBackOnAgentShutdown(new OnAgentShutdownImpl());
/* 3:start communication component */
agent.start("127.0.0.1", false);
/* 4:connect server */
agent.connect("localhost", (short)5555, pdwConnID);
/* 5:handle communication data */
// response OnReceive / OnPullReceive events and receive data
// use agent.send(dwConnID, data, data.length) to send data
/* 6:close communication component */
agent.stop();
/* 7:destroy communication component */
TcpAgent.destroy(agent);
> optimize data transmission / reception strategies:
-----------------
- Server and Agent components provide the following three types of data transmission policy:
1)PACK - packing mode(default) :try to send data formmultiple operetions together to send and add transmission efficiency.
2)SAFE - sage mode :try to make data formmultiple operetions together to send,control the transmission rate ,and avoid buffer overflow
3)DIRECT - direct mode :each sending operation is delivered directly ,for when the loading is not high but it requires real-time high places. - Server and Agent components provide the following two data-accept events:
1)SERIAL - serial mode(default):trigger the same connection in the order: OnReceive and OnClose/OnError event
2)PARALLEL - parallel mode :in different communication threads , trigger the same connection OnReceive and OnClose/OnError event in the same time
> other updates :
-----------------
- IServer‘ GetClientAddress() method changes the name to : GetRemoteAddress()
- IClient‘ Send() method deletes the parameter: “CONNID dwConnID”
- IClient/IServer/IAgent‘ Send() method adds the pointer offset parameter “int iOffset” for sending data buffer
- add EnSendPolicy enumerated type,IServer/IAgent add sending mode setting method: SetSendPolicy()
- add EnRecvPolicy enumerated type,IServer/IAgent add receving mode setting method: SetRecvPolicy()
- IServer/IAgent add method:BOOL GetAllConnectionIDs(),get all connected CONNID
- IUdpServer add method:SetPostReceiveCount(),set Receive Number of predelivery
- EnServerError / EnClientError enumerated type unite into EnSocketError
- EnSocketError / EnHandleResult / EnFetchResult enumerated type moves out of the original class
- IClient/IServer/IAgent add method:BOOL GetPendingDataLength() to get the length of the data which is not issued
- HPSocket4C.dll add method SendPart(),supports assigning the pointer offset parameter for data buffer
- add HPSocket for C# SDK(by int 2e )
- add HPSocket easy language support lib(by Yecate )
- public code package vc-common-src upgrade tp v2.3.5(reference:vc-common-src v2.3.5‘ Change Log)
> update instructions:
-----------------
- HP-Socket v3.2.1 Comply HP-Socket v3.1.3 and previous versions in the functions
- interface changes,it‘s needed to modify the programcode. Notice:the program can be replaced directly by v3.1.3‘ DLL
- EnServerError / EnClientError enumerated type unite into EnSocketError,notice some of the enumerated tyoe changed
==========================================================================================
v3.1.3 upgrade:
==========================================================================================
> add other language Demo:
-----------------
- C#
- Delphi
- E language
> Bug Fixed:
-----------------
- repair IP address misjudgment bug:
1) when client component connnecting to the server,if the IP of the server has full bit(12个numbers:‘AAA.BBB.CCC.DDD’),then judged as the domain name
2) affect component :all TCP/UDP client components
3) affect version:v3.1.2 and all previous versions - repair the domain name and host name‘s IP parsing error bug:
1) when client component connecting to the server by the domain name or host name,it may be resolved to the wrong IP address.
2) affectcomponent :all TCP/UDP client components
3) affect versions:v3.1.2 and all previous versions
> update instructions:
-----------------
1、use HP-Socket v3.1.2 or previous versions for applications can upgrade to HP-Socket v3.1.3 safely
==========================================================================================
v3.1.2 upgrade:
==========================================================================================
> alter the Server component‘s OnClose() / one rror() event‘s trigger rules:
-----------------
- The TCP/UDP Server component of original versions,when you close a connection ,it might also fire the OnClose() event and several one rror() events
- for this possibility,the application need to make OnClose() / one rror() to process the event synchronously
- from v3.1.2 ,when there are OnClose() / one rror() events occuring together,component only notice the first event ,and ignore the left event.
- Therefore,when the application processes the OnClose() / one rror() event , it not need to deal with syschronization,and reduce the possibile bugs and writing or testing code burdens.
Example One:
--------------------------------------------------------------------------------------
ISocketListener::EnHandleResult CServerDlg::OnClose(CONNID dwConnID)
{
// original versions:there are the concurrency of OnClose()/OnError(),put the code in the critical area and test the returned value
CCriSecLock locallock(m_csPkgInfo); // <-- critical area
PVOID pInfo = nullptr;
if(m_Server->GetConnectionExtra(dwConnID, &pInfo) && pInfo != nullptr) // <-- testing the returned value
{
m_Server->SetConnectionExtra(dwConnID, nullptr);
delete pInfo;
}
}
Example two:
--------------------------------------------------------------------------------------
ISocketListener::EnHandleResult CServerDlg::OnClose(CONNID dwConnID)
{
// v3.1.2 version:only receive one OnClose()/OnError() event ,can remove the code out of the critical area and testing the code.
PVOID pInfo = nullptr;
m_Server->GetConnectionExtra(dwConnID, &pInfo);
ASSERT(pInfo != nullptr);
delete pInfo;
}
> other updates :
-----------------
- change TCP Server default parameters :
1) DEFAULT_SOCKET_LISTEN_QUEUE : 300
2) DEFAULT_ACCEPT_SOCKET_COUNT : 300
3) DEFAULT_FREE_SOCKETOBJ_POOL : 150
4) DEFAULT_FREE_SOCKETOBJ_HOLD : 450
5) DEFAULT_FREE_BUFFEROBJ_POOL : 300
6) DEFAULT_FREE_BUFFEROBJ_HOLD : 900 - change UDP Server default parameters :
1) DEFAULT_FREE_SOCKETOBJ_POOL : 150
2) DEFAULT_FREE_SOCKETOBJ_HOLD : 450
3) DEFAULT_FREE_BUFFEROBJ_POOL : 300
4) DEFAULT_FREE_BUFFEROBJ_HOLD : 900
> update instructions:
-----------------
1、 HP-Socket v3.1.1 or previous versions for applications can upgrade to HP-Socket v3.1.2 safely
==========================================================================================
v3.1.1 upgrade:
==========================================================================================
> add export the C function‘s dynamic link library: HPSocket4C.dll:
-----------------
- add the code files: HPSocket4C.h and HPSocket4C.cpp,for creating HPSocket4C.dll
- export the C function and make other language(as:C/C#/Delphi etc)to use HPSocket easily
- HPSocket4C.dll using methods
method one:
--------------------------------------------------------------------------------------
(0) (C/C++ programs)include HPSocket4C.h header files
(1) call ::Create_HP_XxxListener() function to create listener object
(2) call ::Create_HP_Xxx(pListener) function to create HPSocket object
(3) call ::HP_Set_FN_Xxx_OnYyy(pListener, ...) function to set the call back function of listener
(4) call export functions to operate HPSocket object
(5) ...... ......
(6) call ::Destroy_HP_Xxx(pSocket) function to destory HPSocket object
(7) call ::Destroy_HP_XxxListener(pListener) functions to destory the listener object
method two:
--------------------------------------------------------------------------------------
(1) the application need to use the export functions of the package to the specific language class.
(2) after packaging encapsulated,use HPSocket in the OOP way - HPSocket4C.dll dynamic link library (release version)
(1) x86/HPSocket4C.dll - (32bit/MBCS/Release)
(2) x86/HPSocket4C_D.dll - (32bit/MBCS/DeBug)
(3) x86/HPSocket4C_U.dll - (32bit/UNICODE/Release)
(4) x86/HPSocket4C_UD.dll - (32bit/UNICODE/DeBug)
(5) x64/HPSocket4C.dll - (64bit/MBCS/Release)
(6) x64/HPSocket4C_D.dll - (64bit/MBCS/DeBug)
(7) x64/HPSocket4C_U.dll - (64bit/UNICODE/Release)
(8) x64/HPSocket4C_UD.dll - (64bit/UNICODE/DeBug)
> start the Buffer Pool caching mechanism:
-----------------
- Common/Src adds the code file : bufferpool.h and bufferpool.cpp ,and achieve the Buffer Pool caching mechanism
- by the Buffer Pool caching mechanism and enhance the efficiency of memory usage,reduce the dynamic memory allocation and release operation and avoid the memory hole
- CTcpClient use CItemPool and TItemList to achieve transmit buffer
- CUdpClient use CItemPool and TItemList to achieve transmit buffer
- CTcpPullClient use CItemPool and TItemList to achieve transmit bufferand PULL bufferand
- CTcpPullServer use CBufferPool and TBuffer to achieve PULL bufferand
> other updates :
-----------------
- IServer adds the interface method DisconnectLongConnections() to disconnect all long connections.
- IServer deletes interface method GetConnectionCriSec()
- IClient adds methods Get/SetFreeBufferPoolSize()、Get/SetFreeBufferPoolHold() to set the size and threshold of Buffer Pool
- IPullServer deletes methods Get/SetFreePullBufferPool()、Get/SetFreePullBufferHold()
- HPSocket.dll and HPSocket4C.dll use /MT(d) for the options recompile,eliminate dependency on the runtime library
- add the TestEcho-4C testing program,show the using methods of HPSocket4C.dll
> update instructions:
-----------------
- HP-Socket v3.0.2 or previous versions for applications can upgrade to HP-Socket v3.1.1 safely
- if you want to import HPSocket4C.dll into the project , see the way of using HP-Socket,refer to the example project TestEcho-4C
==========================================================================================
v3.0.2 upgrade:
==========================================================================================
> HP-Socket complied as a dynamic link library:
-----------------
- applications can use the HP-Socket by the source code or importing the dynamic link library mode.
- dynamic link library using methods
method one:
-----------------------------------------------------------------------
(0) the application contains the SocketInterface.h and HPSocket.h head files
(1) call HP_Create_Xxx() function to create HPSocket object
(2) after using the call HP_Destroy_Xxx() function to destroy HPSocket object
method two:
-----------------------------------------------------------------------
(0) the application contains the SocketInterface.h and HPSocket.h head files
(1) create the CXxxWrapper wrapper and use the HPSocket object by the smart pointer wrapper. - dynamic link library(release version)
(1) x86/HPSocket.dll - (32bit/MBCS/Release)
(2) x86/HPSocket_D.dll - (32bit/MBCS/DeBug)
(3) x86/HPSocket_U.dll - (32bit/UNICODE/Release)
(4) x86/HPSocket_UD.dll - (32bit/UNICODE/DeBug)
(5) x64/HPSocket.dll - (64bit/MBCS/Release)
(6) x64/HPSocket_D.dll - (64bit/MBCS/DeBug)
(7) x64/HPSocket_U.dll - (64bit/UNICODE/Release)
(8) x64/HPSocket_UD.dll - (64bit/UNICODE/DeBug)
> other updates :
-----------------
- move the component interface and the statement listener to SocketInterface.h
- IServer add interface methods GetConnectionCount()/GetConnectPeriod() and each gets the number of connections and the time of connection.
- IServer interface methods GetListenAddress()/GetClientAddress()‘s CString& change the parameter to LPTSTR
- IClient interface methods GetLocalAddress()‘s CString& change the parameter to LPTSTR
- the function‘s CString& in SocketHelper.h change the parameter to LPTSTR
- the example projects: TestEcho-Pull and TestEcho-PFM use HP-Socket by importing the dynamic link library mode
> update instructions:
-----------------
- HP-Socket v3.0.1 or previous versions for applications can upgrade to HP-Socket v3.0.2
- Beacause some parameters of the interface methods have changed ,so please alter it refer to the example project.
- if the project want to use HP-Socket by the way of a dynamic link library,please refer to the TestEcho-Pull or TestEcho-PFM example project.
==========================================================================================
v3.0.1 upgrade:
==========================================================================================
> add UDP communication component :
-----------------
- add two UDP communication components :CUdpServer as the server component and CUdpClient as the client component
- server component CUdpServer use IOCP communication model
- client component CUdpClient use Event Select communication model
- UDP communication component Interface is the same of the original TCP communication component ,simple and practical
- UDP communication component includes communication line automatic monitoring mechanism
- add UDP communication component example project: TestEcho-UDP
> Code refactoring and optimization:
-----------------
- Specification the name of all Interface、class and code file
- Refactoring and optimization a lot of component code
- server component add the mechanism of read-write lock,effect balance deal-performance and safety
- server component‘s Socket object Cache list set locking the time,upgrade the degree of access-safety
> update instructions:
-----------------
- the Application of using HP-Socket v2.2.3 can safely upgrade to HP-Socket v3.0.1
- because of renaming a lot of Interface、class and code file ,so when system upgrading , this need to relevant change
==========================================================================================
v2.2.3 upgrade:
==========================================================================================
> the data type of connect ID change to ‘CONNID’:
-----------------
- in SocketHelper.h ,it defines as CONNID data type(default:typedef ULONG_PTR CONNID)
- Application can make CONNID defined as it hoped type(eg:ULONG / ULONGLONG ...)
- order to easy to transplant and aegis,Application‘s everywhere should use the‘CONNID’ type quote connect ID
> server Socket component support as every connection tie attached data:
----------------
- IServerSocket and CIocpServer add method Get/SetConnectionExtra()
- Through the above two method ,application can make every connection tie random attached data and take it out
> other updates :
-----------------
- broaden CIocpServer‘s the limit of the number of the biggset IOCP work thread (64 change to 500)
- server Socket component‘s Disconnect() method adds one marked parametric ‘bForce’,directive whether forcibly disconnect connection
- change connect ID‘s generate rule , avert generated number is 0 connection ID
==========================================================================================
v2.2.2 upgrade:
==========================================================================================
> optimization heartbeat checking‘s interrelated function:
-----------------
- IServerSocket and IClientSocket ,theirs Get/SetKeepAliveTimes() method changes to Get/SetKeepAliveTime()
- CIocpServer and CClientSocket ,theirs default KeepAliveTime attribute changes to 5000
- CIocpServer and CClientSocket ,theirs default KeepAliveInterval attribute changes to 3000
==========================================================================================
v2.2.1 upgrade:
==========================================================================================
> Pull modelsupport :
-----------------
- ISocketListener add the method for the Pull model to get the data receiving notification :OnReceive(dwConnID, int)
- add PULL Socket Interface: IPullSocket,the interface‘s Fetch(dwConnID, pBuffer, iLength) method to catch the data of communication
> Server:
-----------------
- server Socket Interface: ISocketServer renamed to IServerSocket
- add PULL Server Socket Listrner abstract class: CPullServerSocketListener
- add PULL Server Socket Listrner: IPullServerSocket
- add PULL Server Socket Implementation class : CIocpPullServer
> Client:
-----------------
- client Socket Interface: ISocketClient renamed to IClientSocket
- client Socket Implementation class :CSocketClient renamed to CClientSocket
- add PULL Client Socket Listrner abstract class: CPullClientSocketListener
- add PULL Client Socket Interface: IPullClientSocket
- add PULL Client Socket Implementation class: CPullClientSocket
> other upgrade:
-----------------
- add PULL Socket testing program: TestEcho-Pull
- In the SocketHelper.h (.cpp) there are some structures for help.
> update instructions:
-----------------
- use HP-Socket v2.1.1 or previous versions for applications can upgrade to v2.2.1 safely
- beacause the names of ISocketServer、ISocketClient and CSocketClient have changed,therefore,the application need to modifie the name and header file name .
==========================================================================================
v2.1.1 upgrade:
==========================================================================================
> Server:
-----------------
- IServerSocketListener cancel OnPrepareSocket(connID, socket) notification method
- IServerSocketListener alter OnAccept((connID, soClient) notification method ,add the parameter :‘soClient’,to achieve the original OnPrepareSocket(connID, socket) notification method function
- IServerSocketListener add OnPrepareListen(soListen) notification method ,to set the listerner to the SOCKET Options of socket
- ISocketServer add method GetListenAddress(strAddress, usPort),to get the address information of the listen to Socket
- ISocketServer add method GetClientAddress(connID, strAddress, usPort),for a connection of a client address.
- the optimization of Socket buffer pools and the managements of memory block buffer pool.
- change the method names for some roperty-accessings
- fix bugs : deadlock phenomenon may happen under special circumstances.
> Client:
-----------------
- ISocketServer add method GetLocalAddress(strAddress, usPort),for get the address information of Client Socket.
- Optimize the data-transmission mode , and improve the efficiency of data transmission
> other upgrade:
-----------------
- TestEcho and TestEcho-PFM testing program optimization
- in SocketHelper.h (.cpp) , there are some functions for help
- for SocketHelper.h ,there are the comments of all interfaces ,classes and methods defined.
==========================================================================================
v2.0.1 upgrade:
==========================================================================================
> Server:
-----------------
- IServerSocketListener add OnPrepareSocket(connID, socket) notice the method for set the SOCKET Options or filter client connection before using the socket
- ISocketServer add method Disconnect(connID) to disconnect the client connections
- add IServerSocketListener‘ subclass CServerSocketListener,provide a default(full) notification processing method
> Client:
-----------------
- IClientSocketListener add OnPrepareSocket(connID, socket) notification method for set the SOCKET Options before using the socket
- support asynchronous Connect:ISocketServer Start() method add one parameter (BOOL bAsyncConnect) set whether to use the asynchronous Connect
- add IClientSocketListener subclass: CClientSocketListener,provide default(null)notification handle methods。
- repair BUG:appear package loss when its ultra-high load
> other upgrade:
-----------------
- support Windows x64 platform
- optimzate TestEcho and TestEcho-PFM testing program.
- TestEcho client adds “asychronous connection” program for example.
- TestEcho server adds “connection filter” and “initiative disconnect ” programs for example