Fixed. Basic operation is good.

Took out stupid client.end()! No wonder the connection dropped.