The code below is suppose to open a connection to a server, send a message and wait for a reply before ending but the problem is it isn't even reaching the end of the function. What could be wrong? Should I use wg sync.WaitGroup
?
func client(servId uint16, servAddr string) {
tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
check(err)
conn, err := net.DialTCP("tcp", nil, tcpAddr)
check(err)
_, err = conn.Write(handshake(servId, 1500))
check(err)
init := make([]byte, 8)
_, err = io.ReadFull(conn, init)
check(err)
fmt.Println("is reached") // doesn't get printed WHY?
fmt.Println(init)
}
How the function above is called from main
// vars
var c, startId, servId uint16
// for each servers
for s := 0; s < len(config.Servers); s++ {
// for each connection
for c = 0; c < config.Total_clients; c++ {
startId = config.Server_id * config.Total_clients
servId = startId + c
servAddr := fmt.Sprintf("%s:%d", config.Servers[s].Host, config.Servers[s].Port)
// create the clients in new go routines
go client(servId, servAddr)
}
}