sendto(sock, bytesToSend.begin(), bytesToSend.size(), 0,
(struct sockaddr *)&destinationAddress, sizeof(struct sockaddr_in));
This could be an issue with my client, but with some trial and error I found if I use the following code to serialize my message my client works great:
kj::byte result[capnp::messageToFlatArray(message).asBytes().size()];
kj::ArrayPtr<kj::byte> bufferPtr = kj::arrayPtr(result, sizeof(result));
kj::ArrayOutputStream arrayOutputStream(bufferPtr);
capnp::writeMessage(arrayOutputStream, message);
sendto(sock, arrayOutputStream.getArray().begin(), arrayOutputStream.getArray().size(), 0,
(struct sockaddr *)&destinationAddress, sizeof(struct sockaddr_in));
Looking at raw bytes that get written I have confirmed the two approaches differ at the packet level. The second, working approach, has 0x10 in the 4th byte, but that's the only difference I see.
My question is, what is capnp::writeMessage(arrayOutputStream, message) doing that my first approach is not? Why can't I just get the bytes and send?
Is my second approach the correct way? Is there a better technique? It seems a little clunky to me - especially the first line where i use
kj::byte result[capnp::messageToFlatArray(message).asBytes().size()];
Thanks again - I appreciate your time.
Noah