To spice things up a little bit,
I've prepared some fun examples. For each example,
I'll read the task, and then I'll show you what the result should look like.
Anyway, you can always find the solutions attached to this very lesson.
Task number one.
Whatever text we send to the Server,
Server returns it in ALL CAPS.
Let's see what that looks like.
I'm going to run several clients right away,
and I'm going to go to - for example - the second client, and I'm going to say "hi" - it returns it in upper
case. And then I'm going to say "exit". It returns "exit" in upper case and then the socket for this client
is closed.
I'm going to go to the first client, and I'm going to say something else - and then I'm going to type "EXIT"
in all caps.
It returns the same thing, and then the socket is closed.
That was the first one - let me close these.
And then let's go to the second.
Our second task is to send some text to the server, and then the server should revert that text backwards,
and send it back to the client.
We end the program by typing in "exit" in the client.
Let's see what that looks like.
Again, I'm going to run ServerMain first, and then one client is enough.
Let's go to clients console.
I'm going to type in "hi", and then "blah blah" and then I'm gonna type in "exit".
So this is what our program for the second task should look like.
I'm going to close the client, terminate the server, and then close the server too.
And I'm also going to close these classes.
Let's look at our third task.
It says that we need a client to connect to the server and then ask the client to guess a number from
1 to 20 - each client gets their own secret
number to guess.
All right.
Let's see what the solution looks like.
I'm going to run ServerMain and then a client.
And then another client. OK I guess this is my second client.
Let's start with guessing.
As soon as I guessed the number I got
"You got it!!!"
message from the server, and then the socket closed. So I can close this client, but I'm left with my first
client so I'm going to try to guess the number here too.
OK.
This time it was eight.
I'm going to close this client too, and terminate the server.
So this is what bonus example 2a should look like.
Let's go to our fourth example, or 2b. This time all of the clients are going after the same number.
So we need to generate one secret number, and you probably can guess it already -
this time we're going to have to generate that number in the ServerMain class.
And then when we run clients - each of the clients is going to be chasing the same number. As soon as one
of the clients guesses the number,
the game is over.
Let's see what that will look like.
I'm going to open my three classes.
I'm going to run ServerMain once, and then I'm going to run two clients
here.
I'm going to say "Harvey" for example, and then I'm going to go to my second client and I'm going to say
"Samantha",
for example.
OK.
Let's get to the guessing part.
OK, I was beginning to think it was going to be the very last number.
So Samantha got the number.
Let's see what's going on with Harvey.
If I try and guess a number here - it's already been guessed.
And this is the message that I get from the server - that Samantha has already guessed the number.
That's all the explanations you'll need.
You can find the solutions attached to this lesson,
but if you have any additional questions, just send me a message or post your question in the Q&A section.