Have you tried getting it to work without sending the output to a socket? That might help you get your head sorted a bit.

That way, at least you'll know that you're echoing the contents properly....