Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>Receives the byte data over the socket.</summary>
- /// <param name="s">The socket to receive data over.</param>
- /// <returns>The received data</returns>
- public static byte[] ReceiveByteData(this Socket s)
- {
- int total = 0;
- int recv;
- byte[] datasize = new byte[4];
- recv = s.Receive(datasize, 0, 4, 0);
- int size = BitConverter.ToInt32(datasize, 0);
- int dataleft = size;
- byte[] data = new byte[size];
- while (total < size)
- {
- recv = s.Receive(data, total, dataleft, 0);
- if (recv == 0)
- {
- break;
- }
- total += recv;
- dataleft -= recv;
- }
- return data;
- }
Advertisement
Add Comment
Please, Sign In to add comment