gotcp
1.0.0
A GO language TCP network library
Combining embed getcp.Session to create your own TCP network session
For example:
type Echo struct {
gotcp. Session
}
func ( this * Echo ) OnRecv ( data [] byte , flag byte ) {
if this . IsVerified () == false {
// ...(业务代码,略)...
this . Verify ()
}
// ...(业务代码,略)...
}
func ( this * Echo ) OnClose () {
// ...(业务代码,略)...
}Register a network session class and enable services
For example:
s := & gotcp. Server {}
s . RegisterSessType ( Echo {})
s . Start ( ":3000" )Combining embed getcp.Session to create your own TCP network session
For example:
type Echo struct {
gotcp. Session
}
func ( this * Echo ) OnRecv ( data [] byte , flag byte ) {
if this . IsVerified () == false {
// ...(业务代码,略)...
this . Verify ()
}
// ...(业务代码,略)...
}
func ( this * Echo ) OnClose () {
// ...(业务代码,略)...
}Connect to the server
For example:
echo := & Echo {}
echo . Connect ( "localhost:3000" , echo )Refer to the following open source libraries:
Test code:
Machine configuration: CPU 16 cores; main frequency 2600
Number of processes: 1 server; 30 clients
Startup script: test.sh
70% CPU of the whole machine
Server program CPU accounts for 25.5% (407.9 / 1600)
23w qps


I'm too lazy to write on the homepage, please refer to: https://blog.csdn.net/u013272009/article/details/96873908