Fix socket message delimiting

Change-Id: I5a510e505d1f2a0ab335c0bd5d3dd92c23331175
More efficient version of the previous fix

Change-Id: Ib7b12040fb07fe0b25ed164428511abd1baa33de