简体   繁体   中英

sending two byte arrays in the same buffer in sockets

I am sending two byte arrays in the same buffer to be sent to a socket i don't know how to separate them when received

clientSocket.SendBufferSize = blindedVote.getBytes().Length + sBEVote.Length;
byte[] outStream = new byte[clientSocket.SendBufferSize];
blindedVote.getBytes().CopyTo(outStream, 0);
sBEVote.CopyTo(outStream, blindedVote.getBytes().Length);
serverStream.Write(outStream, 0, outStream.Length);
// int size = clientSocket.SendBufferSize;
serverStream.Flush();

when received how can i separate each array of bytes?

thanks

It generally depends on your protocol.

You might try creating a specific data structure and send it whole - with the lengths of each array, the actual data, some CRC (it's always good to check data from the socket in one way or another), anything else.

Other option would be to send the length of an array, the first array, wait for some acknowledgement from the receiver, repeat with the second array, etc.

You can't do that without any knowledge of the data on the receiver side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM