begining of change to detect when a bulb lost power (physical switch was turned off) and then came back on.
handle ECONNRESET better.
slightly smarter restart
use close rather than end to catch failures

Conflicts:
	lib/gateway.js
packetType should always be a number
Socket.unref() is not available in Node < 0.10