gotcp
1.0.0
ไลบรารีเครือข่าย TCP ภาษา Go
การรวม Embed getcp.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" )การรวม Embed getcp.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 คอร์;
จำนวนกระบวนการ: 1 เซิร์ฟเวอร์;
สคริปต์เริ่มต้น: test.sh
ซีพียูทั้งหมด 70% ของเครื่องทั้งหมด
CPU โปรแกรมเซิร์ฟเวอร์สำหรับ 25.5% (407.9 / 1600)
23W QPS


ฉันขี้เกียจเกินไปที่จะเขียนในหน้าแรกโปรดดูที่: https://blog.csdn.net/U013272009/article/details/96873908