[EDIT] it seems like this has to do with my laptop's firewall settings rather than anything wrong with the ESP8266 [/EDIT]
I have a webserver on my laptop. When I do this on my ESP8266 (after the wifi has been connected)
while(!client.connect(laptop,port)) {
Serial.println("Connecting...");
delay(1000);
}
It loops forever. However, if I manually ping my ESP from my laptop, I initially get this
Pinging 192.168.1.7 with 32 bytes of data:
Request timed out.
Reply from 192.168.1.7: bytes=32 time=4ms TTL=255
And as soon as this happens, the ESP gets connected to the laptop, and all works fine.
So it seems to me like the client.connect is preventing the ESP from even registering to the network, and the pinging is somehow waking it up.