I am a novice in golang and I am writing a client-server application through the TCP protocol. I need to make a temporary connection, which will close after a couple of seconds. I don't understand how to do that.
I have a such function, which creates a connection and waits for gob data:
func net_AcceptAppsList(timesleep time.Duration) {
ln, err := net.Listen("tcp", ":"+conf.PORT)
CheckError(err)
conn, err := ln.Accept()
CheckError(err)
dec := gob.NewDecoder(conn)
pack := map[string]string{}
err = dec.Decode(&pack)
fmt.Println("Message:", pack)
conn.Close()
}
I need to make this function to wait for data for only some seconds - not forever.