yes it is... here is the full sketch
No, it isn't because this sketch would stay in an endless loop after disconnecting and not connect again. Did you press the reset button in between? If yes, this would have been a quite important information.
If this was the reason, you might have to check what's going on in your network. I use the WireShark tool (Wireshark download | SourceForge.net) to sniff the traffic but I don't know if you already know enough about networks to use such a tool.