Make receive function only get the exact data it needs.

The socket receive function originally grabbed an (essentially) arbitrary amount
of data from the socket meaning that all but the first message received would be
corrupt. In particular, this meant that watching for subscriptions would crash
because the data read would be garbage.