12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package main
- import "net"
- import "time"
- import "fmt"
- import "encoding/binary"
- import "compress/gzip"
- func main() {
- ln, err := net.Listen("tcp", ":7000")
- if err != nil {
- // handle error
- }
- for {
- conn, err := ln.Accept()
- if err != nil {
- // handle error
- continue
- }
- go handleConnection(conn)
- }
- }
- func handleConnection(conn net.Conn) {
- w := gzip.NewWriter(conn)
- for i := int64(0); i < 0x7FFFFFFF; i++ {
- err := binary.Write(w, binary.LittleEndian, i)
- if err != nil {
- fmt.Println(err)
- return
- }
- t := time.Now()
- err = binary.Write(w, binary.LittleEndian, t.UnixNano())
- if err != nil {
- fmt.Println(err)
- return
- }
- err = w.Flush()
- if err != nil {
- fmt.Println(err)
- return
- }
- time.Sleep(100 * time.Microsecond)
- //fmt.Println(i, t)
- }
- }
|