내 서버 모듈의 이진 파일 (Test.bin)을 메모리에 저장된 클라이언트 실행 파일로 보내려고합니다. 서버 측 (C#을)에서 나는이 같은 .BIN을 만듭니다메모리에서 이진 파일 줄 읽기
이public static bool Write(string fileName, string[] write)
{
try
{
using (BinaryWriter binWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
// each write-Array-Segment contains a 256 char string
for (int i = 0; i < write.Length; i++)
binWriter.Write(write[i] + "\n");
}
return true;
}
catch (Exception e)
{
return false;
}
}
그런 다음 내가 같은 클라이언트로 전송 : 클라이언트 측 (C++) 내가받을에
byte[] buffer = File.ReadAllBytes(Program.testFile /*Test.bin*/);
byte[] bytes = BitConverter.GetBytes(buffer.Length);
if (BitConverter.IsLittleEndian)
Array.Reverse((Array)bytes);
this.tcpClient.GetStream().Write(bytes, 0, 4);
this.tcpClient.GetStream().Write(buffer, 0, buffer.Length);
this.tcpClient.Close();
그것을 다음과 같이 저장하십시오 :
DWORD UpdateSize = 0;
NetDll_recv(XNCALLER_SYSAPP, Sock, (char*)&UpdateSize, 4, 0); // what's being first received
unsigned char* Update = new unsigned char[UpdateSize];
if (UpdateSize == 0 || !Network_Receive(Sock, Update, UpdateSize) /*Downloading file into "Update"*/)
{
Sleep(2000);
Network_Disconnect(Sock);
printf("Failed to download file.\n");
}
이 모든 것이 잘 작동합니다. 이제 문제는 :
클라이언트 측의 배열에 서버 측의 파일에 쓴 줄을 어떻게 읽을 수 있습니까? Client-Device에 파일을 저장하고 Streamreader를 사용하고 싶지 않습니다. 메모리에서 읽으려고합니다!
도움을 주시면 대단히 감사하겠습니다. (일부 코드를 제공하는 것이 가장 좋을 것입니다.)
당신이 이진 데이터가 개행 문자를 포함 할 수 없습니다 확신 :
으로는 간단한 예제를 요청? –
새로운 줄 문자 "\ n"이 포함되어 있습니다 ... – xTyrion