main.go 659 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. var connID int
  7. func peocessConn(conn net.Conn, connID int) {
  8. fmt.Println(" ")
  9. var tmp [2000]byte
  10. for {
  11. _, err := conn.Read(tmp[:])
  12. if err != nil {
  13. fmt.Println("read from conn failed", err)
  14. return
  15. }
  16. }
  17. }
  18. func main() {
  19. connID = 0
  20. var connID int
  21. listener, err := net.Listen("tcp", "192.168.32.144:20001")
  22. if err != nil {
  23. fmt.Println("start tcp server 192.168.32.144:20001 failed", err)
  24. return
  25. }
  26. for {
  27. conn, err := listener.Accept()
  28. if err != nil {
  29. fmt.Println("accept failed", err)
  30. return
  31. }
  32. connID = connID + 1
  33. fmt.Println("connID", connID)
  34. go peocessConn(conn, connID)
  35. }
  36. }