I should mention, the above code works fine if my top server is up.
Which board and network stack are you using? I've tried your code on my BCM943341WCD1 on ThreadX/NetX_Duo and cannot replicate the issue. It simply retries the tcp connection again if the server is down.
I've noticed in your code that the return variable is assigned to
wiced_tcp_create_socket() and not wiced_tcp_connect().
Do your results change if you assign result = wiced_tcp_connect()?
For reference, on NetX_Duo the code still goes through fine in my environment whether or not the result variable is correctly assigned.