public void Handle(NetworkStream stream, RequestHeaders headers, TcpClient client) { if (client.Connected) { var bytes = new byte[headers.ChunkSizeBytes]; stream.Read(bytes, 0, bytes.Length); _diskRepository.StreamBytesToFile(headers.FileName, bytes); _jobRepository.UpdateJob(headers); var uploadChunkResponse = new UploadChunkResponse { JobGuid = headers.JobGuid, ChunkNumber = headers.ChunkNumber, Status = JobStatus.Processing }; var jsonResponse = JsonConvert.SerializeObject(uploadChunkResponse); byte[] responseMessage = Encoding.ASCII.GetBytes(jsonResponse); stream.Write(responseMessage, 0, responseMessage.Length); } }