Can you identify whether the connection is successful or not? What error (if any) is reported if you use this code?

Code:
alias test_socket {
  set -e %socket_time $ticks
  sockopen test_socket www.google.com 80 
}
on *:sockopen:test_socket:{
  echo -a Time: $calc(($ticks - %socket_time) / 1000) seconds
  unset %socket_time 
  if ($sockerr > 0) {
    echo -a Connection failed: $sockerr / $sock($sockname).wsmsg
    return
  }
  echo -a Connection successful
  sockclose $sockname
}