...

View Full Version : Need asssistance - Server/Client Random Number game



KungPoo
09-27-2012, 03:38 PM
Good morning everyone,

I have been tasked with a simple project as an interview. I am not requesting anyone show me how to do it, as that will just destroy my learning process, but I am looking for possibly some reference materials. Here is what the game will require:

C# in VS2010


Server will listen on a specific port
Server will allow multiple clients to connect
Client App will connect to server and interpret commands from the user to the server, vice versa
Client App will ask user for upper and lower number fro the guessing range
Client App will then ask user for their guess. If too low or too high, the client will let the user know.
If the user guesses correctly, it will tell the user they are correc,t tell them how many guesses they took, then start the game over.


What I am looking for is some reference materials on how to complete this project. I can complete it as just a simple application, but the whole client/server application programming is new to me.

Please assist.

Thank you kindly,

KungPoo

Spookster
09-27-2012, 04:25 PM
Where the first thing you will want to determine is which network protocol would be best to use for this type of application (i.e. TCP or UDP[multicast/unicast]).

Here is some decent reading to help you decide
http://www.diffen.com/difference/TCP_vs_UDP

KungPoo
09-27-2012, 04:31 PM
With this being a small project, wouldn't a connection-less (UDP) protocol be better, for speed and for the sake of just completing the project?

I know TCP is more connection-oriented- verifying packets, but with such a small project and application, I shouldn't be too worried about packet loss, correct?

Spookster
09-27-2012, 04:55 PM
With this being a small project, wouldn't a connection-less (UDP) protocol be better, for speed and for the sake of just completing the project?

I know TCP is more connection-oriented- verifying packets, but with such a small project and application, I shouldn't be too worried about packet loss, correct?

I wouldn't decide which to use based on "for the sake of just completing the project." Which you use would depend upon the requirements of your app. This is part of the learning process to determine your requirements and make design decisions on how to implement those requirements.

You have a very basic list of requirements right in your post although they are not worded as such. Let's just reword those as more proper type requirements:

REQ01 - Server SHALL listen on a specific port
REQ02 - Server SHALL allow multiple clients to connect
REQ03 - Client App SHALL connect to server and interpret commands from the user to the server, vice versa
REQ04 - Client App SHALL ask user for upper and lower number from the guessing range
REQ05 - Client App SHALL then ask user for their guess and if too low or too high, the client will let the user know.
REQ06 - If the user guesses correctly, it SHALL tell the user they are correct, tell them how many guesses they took, then start the game over.


Now look at each requirement and look at both TCP and UDP and determine if you can implement that requirement using each one. If you can't implement any one of those requirements with one of the protocols then that one should not be selected.

KungPoo
09-27-2012, 05:33 PM
Okay, that helps me understand it a bit better.

So with TCP - This protocol has more features that I will be using with the program. Since it shall allow multiple users to connect to the server, TCP is a better protocol, since it checks the readiness of the receiver. With UDP, it doesn't necessarily do this, and this is a major component of the client/server game in question.

Also, the entire handshake process seems a bit more what this program needs. We want to acknowledge a connection has been made, and transfer data between the connection.

I think TCP would be a lot better choice in regards to what is need to have this program work correctly.


Do you know of any areas that would discuss how to go about implementing this? I know how to get the application to work as just a console application, guess random numbers, but putting this into a client/server relationship is where I am struggling pretty bad right now. I have never dealt with this, so I am at a loss :)

Spookster
09-27-2012, 07:42 PM
Well now if I were tasked with this the next thing I would consider doing is coming up with a design approach. It helps to draw out diagrams of how the software is to be architected. The diagrams can help to visualize how to translate the requirements into modules or layers that you need to code. Since you plan to work with an OOP language that will be beneficial as it will be easier to conceptualize the different objects that you might need. Just glancing at your requirements I might suggest something like:

Server App:
Module 1: Message Processor - provides ability to open/close connections along with creating transmit messages and handles the sending of those, receiving and parsing incoming messages. And would provide an API to other modules to allow them to initiate these functions.

Module 2: Command Processor - Would be in charge of processing the command located in the messages and delegate to any other modules that will be handling the work associated with that command.

Module 3: Game Module - Could contain things like creating the random numbers to any logic needed for determing the results of the guesses.

Module 4: Control Module - Would be the main module in your app that kicks everything off and performs any miscellaneous functionality that doesn't warrant having its own module.

Client App would have a similar design with possibly reused modules in some cases since the client is just acting as the middle man between the user and the server relaying the messages back and forth. Just remember in a client/server relationship its the clients who initiate all transactions and the server just sits there waiting to receive and then respond to those requests.

Here is a decent little article describing that
http://www.ni.com/white-paper/4431/en



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum