Mlti-person chat

This is a discussion on Mlti-person chat within the C++ Programming forums, part of the General Programming Boards category; I am getting problems when a user tries to send text to another user. The information does not seem to ...

  1. #1
    blazen
    Guest

    Mlti-person chat

    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;
    			}
    		}

  2. #2
    blazen
    Guest
    Which else are you talking about? And why does using the recv there go against the idea of select? That recv is there because the client is sending his screen name over to store on the server.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Bush vs. Kerry
    By jlou in forum A Brief History of Cprogramming.com
    Replies: 178
    Last Post: 11-29-2004, 03:45 PM
  3. Requesting Java Chat Client Maintenence
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-02-2003, 01:57 PM
  4. SO close to finishing chat program...!
    By Nakeerb in forum C++ Programming
    Replies: 13
    Last Post: 10-26-2002, 01:24 PM
  5. Rough Portable Chat Design Sketch
    By ggs in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-27-2001, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21