First up "unix sockets" usually refers to "unix domain socket", a special form of IPC.
The null char seems to get thrown away when writing to a socket
That's unlikely. You're probably no writing right.
but this does not seem right
A simpler way would be to precede each "message" with a header containing the length. For example
+---+---------+---+-------+
| 3 | | 5 | ... |
+---+---------+---+-------+
An even simpler approach would be to use a protocol that has notions of messages, i.e. something like UDP or SCTP where a send
equates to at most one recv
.