Original Post
I have to call the function recv twice...at the first time recv will read the first 4 bytes (it''s the int which express the size of a structure, which is serialize in this buffer). This is working well. The second call will read the rest. But there nothing is copied in the buffer without the Zero-Byte.
Here the code:
int bytecounter = 0;
char* recbyte = NULL;
//Information der Größe auslesen
if (recv (daMember[counter].Socket, (char*) &bytecounter, sizeof (int), MSG_PEEK) != sizeof (int))
{
//Socketerror zurückliefern
return SOCKET_ERROR;
}
else
{
cout << bytecounter << endl;
recbyte = new char [bytecounter];
int n = recv (daMember[counter].Socket, recbyte, bytecounter, 0);
char* probe = recbyte;
}
//UI- Struktur füllen
memset (&userinformation, 0, sizeof (UI));
//erstes Byte (BOOLEAN) des Empfangsbuffers in registry kopieren
memcpy (&userinformation[counter].registry, recbyte, sizeof (bool));
//für den Fall eines Gastzuganges
if (userinformation[counter].registry == false)
{
userinformation[counter].nickname = new char [100];
//Nicknamen rauskopieren
memcpy (&userinformation[counter].nickname, recbyte + sizeof (bool), bytecounter - sizeof (bool));
//userinformation[counter].nickname = "hallo";
cout << &userinformation[counter].nickname << endl;
cout << userinformation[counter].nickname << endl;
daMember[counter].myuser = new char [bytecounter];
memcpy (daMember[counter].myuser, userinformation[counter].nickname, bytecounter - sizeof (bool));
}