Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a trivial TCP server leaking sockets.
- package main
- import (
- "fmt"
- "net"
- "time"
- //"io"
- )
- func handle(conn net.Conn, i int) {
- defer conn.Close()
- //io.Copy(conn, conn)
- for {
- fmt.Printf("[%d]",i)
- time.Sleep(time.Second)
- }
- }
- func main() {
- IP := ""
- Port := 5000
- listener, err := net.Listen("tcp4", fmt.Sprintf("%s:%d", IP, Port))
- if err != nil {
- panic(err)
- }
- i := 0
- for {
- fmt.Println("\nstart accepting")
- if conn, err := listener.Accept(); err == nil {
- fmt.Printf("\naccepted %d\n", i)
- i += 1
- if i < 800 {
- go handle(conn, i)
- } else {
- conn.Close()
- }
- } else {
- panic(err)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement