hmm. i always thought an array of size 0 was really one index, but i guess not. oh well, i didn't think about needing room for the '\0' either. so good thing you pointed that out. thank you.
anyways i just realized that i can't use a delimeter for the message because there isn't a byte that is guarenteed to never be sent. so i changed around the code some more, and got some results that i don't even think are possible (i'm guessing something might be wrong with my compiler or at least how i'm trying to compile).
here is the entire function:
Code:
exStr sock_receive()
{
engine::fdset = engine::fds;
engine::sr = select(1, &engine::fdset, NULL, NULL, &engine::selectTime);
if (engine::sr == 1)
{
if (FD_ISSET(engine::esock.sock, &engine::fdset))
{
char
buffer[1024] = "",
flag[6] = "";
engine::exbuff[0] = '\0';
int
rc = 0,
size = 0,
pcount = 0;
do
{
char tbuff[1024];
rc = recv(engine::esock.sock, tbuff, sizeof(tbuff), 0);
tbuff[rc] = '\0';
if (rc == -1)
{
engine::sockRcvErr = -1;
return ("-1");
}
if (rc == 0)
{
engine::sockRcvErr = 0;
return ("0");
}
strcat(buffer, tbuff);
if (rc > 1)
{
size = unpack(buffer[pcount], buffer[pcount + 1]);
pcount += 2;
}
}
while ((rc > 1) && (sizeof(buffer) == size));
while (pcount < rc)
{
unsigned int value = unpack(buffer[pcount], buffer[pcount + 1]);
itoa(value, flag, 10);
pcount += 2;
switch (value)
{
case(0): // creation accept
char instruction[2];
instruction[0] = buffer[pcount];
instruction[1] = '\0';
strcat(engine::exbuff, flag);
strcat(engine::exbuff, instruction);
break;
}
}
engine::sockRcvErr = 0;
return ("wtf");
}
else
{
engine::sockRcvErr = 2;
}
}
else
{
engine::sockRcvErr = 3;
}
return ("1");
}
Code:
void player::send_instruction(char *sbuff, int size)
{
char buffer[size + 2];
pack(size, buffer);
buffer[2] = '\0';
strcat(buffer, sbuff);
int sent = send(get_sock(), buffer, size + 2, 0);
while (sent < size + 2)
{
int n = send(get_sock(), buffer + sent, size - sent + 2, 0);
sent += n;
}
}
i added the return "-1", "0", "wtf", and "1" because i purposely added screwed up my code one time just to see if the errors were working. it turned out that they wern't so i added the returns in and it is still returning an empty string. now how is this possible? there is nowhere in this code that its not returning a constant string, and none of those strings are empty strings.
anyways i'm really greatful that you all have been so helpful. if you could help me get this working i would really appreciate it. thank you for all your help so far.