gotcp
1.0.0
一個GO語言TCP網絡庫
組合嵌入gotcp.Session,製作自己的TCP網絡會話
例如:
type Echo struct {
gotcp. Session
}
func ( this * Echo ) OnRecv ( data [] byte , flag byte ) {
if this . IsVerified () == false {
// ...(业务代码,略)...
this . Verify ()
}
// ...(业务代码,略)...
}
func ( this * Echo ) OnClose () {
// ...(业务代码,略)...
}註冊網絡會話類,開啟服務
例如:
s := & gotcp. Server {}
s . RegisterSessType ( Echo {})
s . Start ( ":3000" )組合嵌入gotcp.Session,製作自己的TCP網絡會話
例如:
type Echo struct {
gotcp. Session
}
func ( this * Echo ) OnRecv ( data [] byte , flag byte ) {
if this . IsVerified () == false {
// ...(业务代码,略)...
this . Verify ()
}
// ...(业务代码,略)...
}
func ( this * Echo ) OnClose () {
// ...(业务代码,略)...
}連接服務器
例如:
echo := & Echo {}
echo . Connect ( "localhost:3000" , echo )參考了以下開源庫:
測試代碼:
機器配置: CPU 16核; 主頻2600
進程數: 1 服務器; 30 客戶端
啟動腳本: test.sh
整機CPU 70%
服務器程序CPU 佔25.5% ( 407.9 / 1600 )
23w qps


懶得在主頁上寫了,請參考: https://blog.csdn.net/u013272009/article/details/96873908