bttcp is a binary transmission protocol based on TCP, where the response header only records the length of the binary stream and data exchange is limited to byte exchange. bttcp is designed to improve transmission performance.
Select the version to install
go get github.com/go-needle/bttcp@version
If you have already get , you may need to update to the latest version
go get -u github.com/go-needle/bttcp
package main
import "github.com/go-needle/bttcp"
func main() {
s := bttcp.NewServer(bttcp.HandlerFunc(func(b []byte) []byte{
return b
}))
s.Run(9999)
}
package main
import (
"fmt"
"github.com/go-needle/bttcp"
"math/rand"
"strconv"
"sync"
"time"
)
var wg sync.WaitGroup
func main() {
c := bttcp.NewClient("127.0.0.1:9999", 100, true)
for i := 0; i < 10000; i++ {
wg.Add(1)
num := i
go func() {
time.Sleep(time.Duration(rand.Intn(100)) * time.Second)
resp, err := c.Send([]byte("hello" + strconv.Itoa(num)))
if err != nil {
return
}
fmt.Println(string(resp))
wg.Done()
}()
}
wg.Wait()
c.Close()
}