num.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import "net"
  3. import "time"
  4. import "fmt"
  5. import "encoding/binary"
  6. import "compress/gzip"
  7. func main() {
  8. ln, err := net.Listen("tcp", ":7000")
  9. if err != nil {
  10. // handle error
  11. }
  12. for {
  13. conn, err := ln.Accept()
  14. if err != nil {
  15. // handle error
  16. continue
  17. }
  18. go handleConnection(conn)
  19. }
  20. }
  21. func handleConnection(conn net.Conn) {
  22. w := gzip.NewWriter(conn)
  23. for i := int64(0); i < 0x7FFFFFFF; i++ {
  24. err := binary.Write(w, binary.LittleEndian, i)
  25. if err != nil {
  26. fmt.Println(err)
  27. return
  28. }
  29. t := time.Now()
  30. err = binary.Write(w, binary.LittleEndian, t.UnixNano())
  31. if err != nil {
  32. fmt.Println(err)
  33. return
  34. }
  35. err = w.Flush()
  36. if err != nil {
  37. fmt.Println(err)
  38. return
  39. }
  40. time.Sleep(100 * time.Microsecond)
  41. //fmt.Println(i, t)
  42. }
  43. }