Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    would be be better if i post the client and server code up?
    Post your complete client and server code.
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    54
    Rep Power
    3
    done
    Last edited by lucki_87; December 4th, 2012 at 04:21 AM.
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    54
    Rep Power
    3
    done
    Last edited by lucki_87; December 4th, 2012 at 04:21 AM.
  6. #19
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,253
    Rep Power
    2222
    Originally Posted by lucki_87
    Isn't TCP/IP the protocol I specified?
    Rather TCP/IP is a suite of several protocols that work together in the different layers. For example, in the transport and IP layers two of the protocols are TCP and UDP; you have chosen to use TCP.

    Additionally, the applications themselves in the application layer need a protocol to talk to each other; eg, HTTP for your web browser to talk with a web server. An analogy for UDP is exchanging letters through the mail and for TCP an analogy is a telephone conversation. You can think of TCP/IP as the telephone and all the phone company's facilities that enable you to call somebody and to talk with them, but you still need to know how conduct that conversation over the phone, which would be your application-layer protocol.

    My question was as it has been from the start: what is your application-layer protocol?

    Originally Posted by lucki_87
    my c programming skill is 4 months

    my assignment is suppose to be a simple one but with all this packets and protocols talks i am more confused then ever
    I am very surprised that you'd be given a networking assignment in a beginning C class. Could you please show us your assignment instructions? I can't help but wonder if you're going beyond your requirements.

    And I assure you that my talk of packets and protocols is an essential and fundamental part of network programming. When this assignment is over and you have some free time, you would do well to start reading up on TCP/IP and how it works so that you can use that information in later programs.

    Originally Posted by lucki_87
    would be be better if i post the client and server code up?
    Yes it would. Along with the assignment instructions. I suspect that there is some confusion.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    54
    Rep Power
    3
    done
    Last edited by lucki_87; December 4th, 2012 at 04:21 AM.
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Well, first of all I believe both your client and your server code should be in one executable file because of the following requirements:

    o The user may specify an IP address in the command line or not. If an IP address is specified, the game process takes on the role of a client and connects to the other game process executing at the specified IP address, using TCP/IP sockets. If no IP address is specified, then the game process takes on the role of a server and waits for another game process to initiate a connection.
    o When a player wins, s/he is prompted to either play another game or quit. The losing player does not get a choice and must play again if the winner chooses to do so. If the winner decides to play again, s/he becomes the oracle, and a new game starts up. If the winner decides to quit, his game process terminates, and the losing player's game process turns into server mode and waits for another game process to establish an new connection.
    The first point indicates that the command line input determines whether the binary will be started as a client or a server. The second point indicates that running process can be switched from client to server mode and vice versa. Thus, you need both the client and server code in one executable.

    I would also suggest that you use a structure to pass data to/from the client and server. For example:

    Code:
    struct sendmsg
    {
    int processcode;
    char mychar;
    char myword[128];
    };
    Where processcode could be an indicator that you are sending a char which is loaded in mychar or a string which is loaded in myword. Also, processcode could be used to indicate that a swap is required as indicated above where the client becomes the server and the server becomes the client. Obviously, you would use a switch statement to determine what action to take in the client or server dependent upon the value of processcode.

    Comments on this post

    • lucki_87 agrees : thanks
  12. #22
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,253
    Rep Power
    2222
    Originally Posted by BobS0327
    Well, first of all I believe both your client and your server code should be in one executable file ...
    That need was expressed up-front, but there was so much confusion at first -- indeed, we were only recently told that this is a school assignment -- that we were trying to keep things simpler at first.

    Originally Posted by BobS0327
    I would also suggest that you use a structure to pass data to/from the client and server.
    Bad idea! Very bad idea!
    Declare a struct and print out its sizeof(). Then by hand calculate what that sizeof() value should be. They don't match, do they? Now compile that same code with different compilers on different computers with different operating systems. Do they all report the same sizeof() of the identically same struct? I would very much doubt it.

    Because of the computer's hardware design, especially the bus size, word boundaries make memory access to certain memory locations faster and more efficient -- accessing on a word boundary is what the computer was designed to do, but accessing one byte past a word boundary takes more work and is slower. Therefore, compilers will optimize structs by adding "padding characters" between the fields of the struct in order to put as many of those fields as possible on a word boundary. And since different compilers will do this differently, especially if the computer has a different bus size, the same struct will end up having different padding and the fields will not line up. This problem is far worse in networking, so that the struct you send to another computer will arrive intact, but incomprehensible to that other computer.

    Now, it does make sense to use a struct within your code, but you then need to explicitly insert and extract each individual field into and out of the packet, after having explicitly specified the offset, size, and format of each and every field in that packet.

    Read my Formatting Packet Data page for a more complete discussion.

    Now I'm late for work.

    Comments on this post

    • lucki_87 agrees : thanks for the help, i caused you some frustrations
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    54
    Rep Power
    3
    ty for the help

    now i am getting somewhere with this assingment

    we are using the same vm across platform
    so in that essence sending the raw packet would be okay?
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    we are using the same vm across platform
    so in that essence sending the raw packet would be okay?
    I'm not sure I understand what you mean by a "raw packet" in relation to your school assignment. A "raw packet" to me is a complete layer two network frame that is sent to the physical wire which primarily is used to manipulate the target and source MAC addresses and layer 3 protocol fields. I don't see any connection between this and your school assignment.

    Thus, please elaborate on what you mean by a "raw packet".
  18. #25
  19. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,253
    Rep Power
    2222
    As BobS0327 says, a "raw socket" has a very definite and specific meaning, besides which working with raw sockets is very low-level and hence a much more advanced topic.

    That assignment is somewhat above the level that I would expect for a class with only four months of programming experience. Did you sign up for a class that had a prerequisite level of experience higher than you actually possess?

    Anyway, the more immediate question would be what your current problem is. If you ask specific questions while providing us with pertinent information, then we can address your problems more directly.

    For example, if your code listings are still current, the main thing I see missing is any processing of the packets either the client or server receives. Have you worked that out yet? Or is that your current problem?
  20. #26
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Originally Posted by dwise1_aol
    That need was expressed up-front, but there was so much confusion at first -- indeed, we were only recently told that this is a school assignment -- that we were trying to keep things simpler at first.


    Bad idea! Very bad idea!
    Declare a struct and print out its sizeof(). Then by hand calculate what that sizeof() value should be. They don't match, do they? Now compile that same code with different compilers on different computers with different operating systems. Do they all report the same sizeof() of the identically same struct? I would very much doubt it.

    Because of the computer's hardware design, especially the bus size, word boundaries make memory access to certain memory locations faster and more efficient -- accessing on a word boundary is what the computer was designed to do, but accessing one byte past a word boundary takes more work and is slower. Therefore, compilers will optimize structs by adding "padding characters" between the fields of the struct in order to put as many of those fields as possible on a word boundary. And since different compilers will do this differently, especially if the computer has a different bus size, the same struct will end up having different padding and the fields will not line up. This problem is far worse in networking, so that the struct you send to another computer will arrive intact, but incomprehensible to that other computer.

    Now, it does make sense to use a struct within your code, but you then need to explicitly insert and extract each individual field into and out of the packet, after having explicitly specified the offset, size, and format of each and every field in that packet.

    Read my Formatting Packet Data page for a more complete discussion.

    Now I'm late for work.
    Very interesting. But I'm curious as to how you account for the C99/C11 and the ANSI/ISO C++ standards coupled with the ancillary network functions being used to address the network byte order to native byte order conversion and vice versa. That is, your explanation doesn't appear to address any of the programming standards and their bearing on the protocol. Also, I didn't find any of the standards info on your website.
  22. #27
  23. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,253
    Rep Power
    2222
    First you gave bad advice about sending structs and now you change the subject to byte order? So if you truly have any of this special knowledge that you're trying to brag about, present it. If there are any special tricks in C99/C11 with respect to padding characters in structs, then shouldn't you have informed the OP about them? And exactly what standards are you saying that are missing on my site? I point my readers to the RFCs, which are the Internet standards.

    Just because you didn't know about padding characters doesn't mean you have to resort to empty posturing. A fragile ego is the last thing a programmer can afford to have.

    PS

    FWIW, I have worked as a professional software engineer since 1982, therefore at least three decades. Mind you, the first decade was working in Pascal, since it was then viewed as a stepping-stone to Ada, the then-be-all of structured programming. I have been working since 1990 in C and C++, so then more than two decades.

    With all due respect, in all that time, absolutely nobody I know of works with C99. When we talk C, we are talking C89, AKA "ANSI C". And here you're talking of "C11". Are there even C11-compliant compilers? I personally lived through the "Ada verification" era, so I know how that played out. You want to invoke "C11"? Just who exactly is completely "C11 compliant"?

    What is your own professional experience? Or are you purely an academic, completely ignorant of the professional software environment?
    Last edited by dwise1_aol; December 4th, 2012 at 03:47 AM.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo