Ok, so I'm attempting to take my last look at buffer "leftovers" as a problem. I'm trying to deal with sending ip's over a network, dynamic ips. That means I need to be able to send an 11 character ip, 15 character ip, then 13 character ip. The problem I'm having is whenever i request to see my ip with my command "-ip"(doesn't really matter but whatever), the output is as such:
Quote:
there is apparently 19 characters(20 including '\0' character?), so what I'm thinking is that the client is requesting more data than I want it to, causing the server to send the extra "2.168.1." off the first ip. Here's what I have:
//server recv cmd
void Server::Recv_msg()
{
// Receive buffer on character array recvbuf
if ((bytes = recv(i, recvbuf, 10, 0)) <= 0)
{
// If no data received, remove client from userlist
Remove_client();
}else if(!strcmp(recvbuf, "-ip")){
for(int h = 0; h < my_vec.size(); h++){
tempuser2 = my_vec.at(h);
if(tempuser2.name=="client")
for(j = 0; j <= fdmax; j++)
{
// if socket j is in the set, send to that socket
if (FD_ISSET(j, &master))
{
// Send recvbuf to all users
send(j, tempuser2.ip.c_str(), strlen(tempuser2.ip.c_str()), 0);
}
}
}
}else{
// If data was received, send to all users
Send_msg(); // Doesnt matter to us though
}
}
//client recv
void Client::RecvMessage()
{
// sockfd: Socket in which data is received
// recvbuf: Char in which data is received (as a string)
// 256: Max bytes to receive from the server
while (bytes = recv(sockfd,
recvbuf,
10,
0) == -1)
// Output error message if error occurs
{ Msges.ErrorMsg("Error while receiving."); }
myLog.open(logname.c_str(), ios::app);
myLog << recvbuf;
myLog.close();
cout << recvbuf;
}
I know the problem is with the client receiving because he won't always receive 10 bytes of data. This is what I'm trying to figure out.