adb sometimes won't connect untill after a lot of tries, and sometimes never adb sometimes won't connect. I get this behaviour. What's going on?

$&gt; adb kill-server
[ user@host ] ~
$&gt; adb connect 192.168.3.160:5556
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.3.160:5556
[ user@host ] ~
$&gt; adb shell
error: device offline
[ user@host ] ~
$&gt; adb connect 192.168.3.160:5556
already connected to 192.168.3.160:5556
[ user@host ] ~
$&gt; adb shell
error: device offline


(Note: It also occurs with adb using port 5555)
I would write this as a comment but I can't. It may be because of the cable. I had this problem with an old cable that kept disconnecting my phone. Even cables that look fine may do this. The problem went away after I bought a new cable.