#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0

    Question hello again, some probs in C++ server program


    Hello all
    i have to now do a C++ server and Java client (opposite of what i asked you people b4),
    Now when i am compling my C++ server, its giving some erros in windef.h like

    warning c4091: 'typedef' : ignored on left of struct...........
    error C2143: syntax error: missing ; before constant
    fatal error C1004: unexpected end of line found

    the code of main program is like this (it shows error in this part i think, when i compile files individually)

    #include "server.h"

    #define SIZE 10
    #define NUM_PACKS 3

    void main(int argc, char *argv[])
    {
    // double C[SIZE];
    // char D[SIZE];
    int A[SIZE];

    int port = 5010;
    int dataport = 5011;

    WSADATA WsaDat;
    if(WSAStartup(MAKEWORD(1,1), &WsaDat) != 0)
    {
    printf("WSA initialization failed");
    }

    if (argc>2)
    {
    port = (int) atol(argv[1]);
    dataport = (int) atol(argv[2]);
    }

    Server mylink(port, dataport);

    for (int i=0; i<SIZE; i++)
    {
    // C[i] = (double) i*i+0.5;
    // D[i] = i;
    A[i] = i*i;
    }
    mylink.connect();

    for (int i=0; i<NUM_PACKS; i++)
    {
    // mylink.send_bytes(D, SIZE);
    // mylink.recv_doubles(C, SIZE);
    mylink.send_ints(A, SIZE);
    }

    mylink.closesocket();
    WSACleanup();
    printf("Server: Closing socket");
    }


    Please help me out,

    Thanx

    Regards
    Max
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    Are you sure that the error isn't in server.h?
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    I second the suspicion that it is in the server.h header file, since the keyword "typedef" does not appear in the .cpp source file.

    Check the lines immediately preceding the one containing the typedef that it's complaining about. Make sure that you did not leave a semicolon off the end of a class or struct declaration.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0
    hi
    this is server.h


    #define BUFFSIZE 64000

    #include <winsock.h>
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    class Server
    {
    // class attibutes
    public:
    int port; // the port I'm listening on
    int dataport; // the port I'm listening for datagrams on
    int REVERSE; // should be reverse the incoming/outgoing
    // byte order, 0 is normal, 1 is reversed

    protected:
    int sockfd; // listen on sock_fd
    int datasockfd; // listen on datagram socket
    int senddatasockfd; // datagram send socket
    int new_fd; // new connection on new_fd
    struct sockaddr_in my_addr; // my address information
    struct sockaddr_in their_addr; // connector's address information
    struct sockaddr_in dest_addr; // used for datagram sending, not
    // sure why we can't use their_addr, oh well
    int sin_size;
    double buffer[BUFFSIZE]; // reuse the same memory for buffer
    double buffer2[BUFFSIZE];

    // class methods
    public:
    Server(int, int); // constructor with port #
    void connect(); // accept a new connection
    void closesocket(); // close the socket

    void send_string(char *str); // send a string to socket
    void send_bytes(char *vals, int len); // send some bytes
    void send_ints(int *vals, int len); // send some integers
    void send_floats(float *vals, int len); // send some floats
    void send_doubles(double *vals, int len); // send some doubles
    void send_datagram(char *vals, int len); // send a datagram packet
    int recv_string(char *str, int max, char term); // recv a string
    int recv_bytes(char *vals, int max); // recv bytes
    int recv_ints(int *vals, int max); // recv ints
    int recv_floats(float *vals, int max); // recv floats
    int recv_doubles(double *vals, int max); // recv doubles
    int recv_datagram(char *vals, int max); // recv datagram
    void recv_ack();
    void send_ack();

    };

    when i click on the error part, actually it goes to the windef.h and on this line

    /****************************************************************************
    * *
    * windef.h -- Basic Windows Type Definitions *
    * *
    * Copyright (c) 1985-1997, Microsoft Corp. All rights reserved. *
    * *
    ****************************************************************************/


    .
    .
    .
    typedef struct tagSIZE
    {
    LONG cx;
    LONG cy;
    } SIZE, *PSIZE, *LPSIZE; //the coursor comes here when i click on error
    .
    .
    .

    All 3 errors goes to this line, the errors are like this again

    c:\program files\microsoft visual studio\vc98\include\windef.h(322) : warning C4091: 'typedef ' : ignored on left of 'struct tagSIZE' when no variable is declared
    c:\program files\microsoft visual studio\vc98\include\windef.h(322) : error C2143: syntax error : missing ';' before 'constant'
    c:\program files\microsoft visual studio\vc98\include\windef.h(322) : fatal error C1004: unexpected end of file found



    Now what to do for it, why does it goes to windef.h,

    Max
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0
    hey all
    any info on my question

    Max
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Originally posted by Max_2003
    hi
    this is server.h
    . . .
    .
    .
    .
    typedef struct tagSIZE
    {
    LONG cx;
    LONG cy;
    } SIZE, *PSIZE, *LPSIZE; //the coursor comes here when i click on error
    .
    .
    .

    All 3 errors goes to this line, the errors are like this again

    c:\program files\microsoft visual studio\vc98\include\windef.h(322) : warning C4091: 'typedef ' : ignored on left of 'struct tagSIZE' when no variable is declared
    c:\program files\microsoft visual studio\vc98\include\windef.h(322) : error C2143: syntax error : missing ';' before 'constant'
    c:\program files\microsoft visual studio\vc98\include\windef.h(322) : fatal error C1004: unexpected end of file found



    Now what to do for it, why does it goes to windef.h,

    Max
    Error messages are almost never easy to decipher. In school, I found the IBM/370's error messages almost worthless. At least these error messages pointed us to the location of the problem. The problem is indeed in the typedef declaration for the struct.

    Here is how Microsoft's Visual C++ v6 help describes typedef'ing a struct:
    typedef struct club
    {
    char name[30];
    int size, year;
    } GROUP;

    This statement declares GROUP as a structure type with three members. Since a structure tag, club, is also specified, either the typedef name (GROUP) or the structure tag can be used in declarations. You must use the struct keyword with the tag, and you cannot use the struct keyword with the typedef name.
    In the above example, the tag, club, is optional. What is required is the new type name, which is GROUP. To my knowledge, you cannot declare variables of the new type inside of the typedef, which appears to be what you were trying to do. Even if there were a way to do it, it would make the code less readable and so would be a bad idea. Keep the typedef and variable declarations in separate statements.

    I don't know whether you are allowed to declare more than one new type name, but the pointer notation is definitely wrong.

    I assume that your intention is to typedef a new type called SIZE and then declare two pointer variables called PSIZE and LPSIZE. Following that assumption, here is what I think you intended to write:
    Code:
    // define the new type called SIZE
    typedef struct 
    {
       LONG        cx;
       LONG        cy;
    } SIZE;   
    
    // declare two pointers to type SIZE
    SIZE  *PSIZE, *LPSIZE;
    Notice that I left out the tag since it is not needed.

    Now, if you were indeed wanting to create three new types, here is how I would do it:
    Code:
    // define the new type called SIZE
    typedef struct 
    {
       LONG        cx;
       LONG        cy;
    } SIZE;   
    
    // typedef the other two types based on the SIZE type
    typedef SIZE*  PSIZE;
    typedef SIZE*  LPSIZE;
    
    // some sample variable declarations:
    SIZE  size;        // a struct variable
    PSIZE pSize;     // a pointer variable
    LPSIZE pLSize;  // another pointer variable
    If it's any consolation, almost every time I typedef a struct, I have to go back and look up the syntax. I guess I'm just a slow learner.
    Last edited by dwise1_aol; September 10th, 2003 at 12:29 PM.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0
    hey dwise
    oh its pretty complicated, why its giving error in windef.h, i didn't do anything it, or is it that some declarations of mine are conflicting it,
    i don't understand it, what really is the problem

    is it with some linking error, i have linked wsock32.dll also,

    Max
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0
    hey
    i tried using the command line tools, and it worked too, oh this GUI stuff

    Max
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    That typedef is correct in form. It is quite normal to define a struct type and pointers to that type in one typedef. MS does it all over the place. In fact, windef.h is one of their files. Could the error have anything to do with the fact that you are doing a #define of SIZE in your code. I can see that confusing the compiler.
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0
    i think i will try to change the SIZE variable, n then try again with all new project,
    hope it works

    Max
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    Assuming that you mean your #define I think that is a good starting point.
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    29
    Rep Power
    0
    hey
    ya it worked now,
    i changed the name of the #define and also deleted some prebuilt heard files called .pch and redbuild the project

    it worked fine

    Max

IMN logo majestic logo threadwatch logo seochat tools logo