package main import ( llog "github.com/TransX/log" "github.com/TransX/protocol" "github.com/davecheney/profile" "io/ioutil" "log" "math/rand" "net/http" "sync" "time" ) var mux sync.Mutex var benchSeed int func transClient() { t := protocol.NewTransTCP() t.Start("1200", "127.0.0.1", "1201", "client") } func transServer() { t := protocol.NewTransTCP() t.Start("1201", "192.168.56.101", "80", "server") } func doHttp(c chan int) { resp, err := http.Get("http://127.0.0.1:1200/test.bin") if err != nil { log.Println("could not get:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) log.Printf("got %d bytes\n", len(body)) if err != nil { log.Println("not get:", err) } else { } c <- 0 } func randMillionSecond() time.Duration { mux.Lock() benchSeed++ defer mux.Unlock() s := rand.NewSource(int64(benchSeed)) r := rand.New(s) return time.Duration(r.Int() % 1000) } func attack() { c := make(chan int) for i := 0; i < 10; i++ { time.Sleep(time.Millisecond * randMillionSecond()) go doHttp(c) } for i := 0; i < 10; i++ { <-c } log.Println("Finish") } func main() { llog.LogTo("applog/log.txt", "DEBUG") defer profile.Start(profile.CPUProfile).Stop() benchSeed = 0 go transClient() go transServer() attack() }