Chat program

This is a discussion on Chat program within the C++ Programming forums, part of the General Programming Boards category; I am doing a project for class as you may already know which is a multi-user chat program. I am ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    99

    Chat program

    I am doing a project for class as you may already know which is a multi-user chat program. I am in the final stages of writing the code or in a better saying I am trying to get rid of the errors that prevent me from running it. Several of the errors complain of when I call a member function of a class (have to use a class blah!) and the compiler confuses it with a structure call:
    Code:
    Error E2294 SERVER.CPP 92: Structure required on left side of . or .* in functio
    n main()
    
    FD_SET(newfd, &master); // Add to set
    if (newfd > fdmax)    // Keep track of the maximum
          fdmax = newfd;
    announ = newuser( i );
    tserv.announce(announ, fdmax, listener); 
    // Print status to console
    cout << "selectserver: new connection from " << inet_ntoa(client.sin_addr) << " on socket " << newfd << endl;
    Also I get this error:
    Code:
    Error E2034 list.h 122: Cannot convert 'int' to 'char *' in function newuser(int
    ,sockaddr *)
    
    char *newuser( int sockfd, struct sockaddr *info )
    {
    	char *ip, *tmp;
    	int sin_size = sizeof( info );
    
    	recv( sockfd, tmp, length, 0);
    	if( getpeername( sockfd, ( struct sockaddr *)&info, &sin_size ) == 0 )
      		cout << "Invalid client" ;
    	else
    	{
    		ip = inet_ntoa( info.sin_addr );
    		adduser( ip, tmp );
    	}
    	return *tmp;
    }
    Help is apprieciated.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    I will just show you the full with error lines. They are in the zip file.
    Attached Files Attached Files

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>char *newuser( int sockfd, struct sockaddr_in *info )

    >>ip = inet_ntoa( info->sin_addr );

    >>announ = newuser( i, &client );

    >>tal0n_ tserv; <-- No brackets
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    >> int sin_size = sizeof( info );

    This will always return 2 on 16-bit, 4 on 32-bit or 8 on 64-bit.

    You're retrieving the byte size of the pointer, not the element count of the array. You have to pass that in a separate parameter.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Unreg1
    Guest
    Originally posted by CornedBee
    >> int sin_size = sizeof( info );

    This will always return 2 on 16-bit, 4 on 32-bit or 8 on 64-bit.

    You're retrieving the byte size of the pointer, not the element count of the array. You have to pass that in a separate parameter.
    I expect he actually wants
    >>int sin_size = sizeof( *info );
    to get the size of the struct.

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    I thank you all for your help. Mainly they were just little mistakes but I thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 09:49 PM
  3. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 08:48 AM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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