making it short:
a server(192.168.0.78) listens on 8013
a client(10.0.2.15) tries to connect the server, getting its local port(eg.54591)
how to make the client close the connection and reuse 54591?
i tried and got:
1. close the connection directly and listen the same port:can not reuse port
2. launch another program(B) to connect server and exit, then tried to listen the port B has used:unknown port
is there a correct way to do this?
code is simple:
client
func main() {                                                                                                                    
    conn, err := net.Dial("tcp" , "192.168.0.78:8013")                                                                           
    if err != nil {                                                                                                              
        panic(err)                                                                                                               
    }                                                                                                                            
    localAddr := conn.LocalAddr().String()                                                                                       
    conn.Close()                                                                                                                 
    // i got the local port, what to do?                                                                                         
    fmt.Println(localAddr)                                                                                                       
}      
server
func main(){                                                                                                                     
    ln, err := net.Listen("tcp", ":8013")                                                                                        
    if err != nil {                                                                                                              
        panic(err)                                                                                                               
    }                                                                                                                            
    for i := 0; i < 5; i++ {                                                                                                     
        conn, err := ln.Accept()                                                                                                 
        if err != nil {                                                                                                          
            panic(err)                                                                                                           
        }                                                                                                                        
        fmt.Println(conn.RemoteAddr().String(), "connected")                                                                     
        conn.Close()                                                                                                             
    }                                                                                                                            
}  
 
     
     
    