basically all of the socket events have a $sockerr identifier which is > 0 when there is an error. Hence in all your sock events (most importantly, sockopen and sockread), you should have something like this at the top of each event:

if ($sockerr) {
echo -a Error: $sockerr
return
}

You can also get the textual error message by specifying a property.