Exemplo n.º 1
0
        public static DataTransferResult RecieveData(Socket socket)
        {
            DataTransferResult result = new DataTransferResult();
            int dataLength;

            int headerLength = HeaderConstants.GetLength();
            var headerBytes  = new byte[headerLength];
            int received     = 0;

            while (received < headerLength)
            {
                received += socket.Receive(headerBytes, received, headerLength - received, SocketFlags.None);
            }

            Header header = new Header(headerBytes);

            result.Header = header;
            dataLength    = header.GetDataLength();

            var data = new byte[dataLength];

            received = 0;
            while (received < dataLength)
            {
                received += socket.Receive(data, received, dataLength - received, SocketFlags.None);
            }

            var word = Encoding.UTF8.GetString(data);

            result.objectResult = word;
            return(result);
        }
Exemplo n.º 2
0
        public static string DecodeMessage(byte[] codedMessage)
        {
            string decodedMessage;
            int    index = HeaderConstants.GetLength();
            int    count = codedMessage.Length - index;

            decodedMessage = Encoding.UTF8.GetString(codedMessage, index, count);

            return(decodedMessage);
        }