I am getting problems when a user tries to send text to another user. The information does not seem to get there. It is either in how the client reads from the server or in how the server handles and sends the information so I will include both parts:
Server
Code:
for ( int i=0; i <= fdlarge; i++ )
{
if ( FD_ISSET(i, &tmp) )
{
if (i == top)
{
// Handle new connections
int size = sizeof(client);
if ((newfd = accept(top, (struct sockaddr *)&client, &size)) == -1)
cout << "Error in Accept";
else
{
con[count++] = i;
FD_SET(newfd, &master); // Add to set
if (newfd > fdlarge)
fdlarge = newfd;
recv( newfd, name, 30, 0);
announ = newuser( i, name, &client );
tserv.announce(announ, con, count);
// Show Status
cout << "selectserver: new connection from " << inet_ntoa(client.sin_addr) << endl;
}
}
else
{
if ( (bytes = recv( i, buf, sizeof(buf), 0)) < 0 )
{
cout << i << " disconnected";
closesocket(i);
FD_CLR(i, &master);
return 1;
}
else
{
user = getuser( tserv.getIp( i, &client ) );
for ( int j=0; j <= fdlarge; j++ )
{
if ( j != top )
{
user = strcat( user, ": " );
user = strcat( user, buf );
send( j, user, strlen(user), 0 );
}
}
}
}
}
Client
Code:
if (FD_ISSET(top, &readfds))
{
if (recv(top, rec, sizeof(buf), 0) <= 0)
{
cout << "Server disconnected." << endl;
return 0;
}
else
{
rec[strlen(rec) + 1] = '\0';
cout << rec << endl;
}
}