Before we continue, I realized that I forgot to do just a couple of things.
So I want to make sure that we're all squared away before we continue on in libraries.
We need to add this line to our server as well.
And then inside of client, we need to add in use chat server client.
That way we can reference our enum types, client and server.
And then we also want to bring in use standard sync arc.
And so once we have that, now we have enough implemented to allow us to create our main function inside
of our client.
So the first thing that we want to do is actually bring in another import.
So we want to bring in async standard and then task.
And now we can start implementing in our main function, which is going to return a chat result.
And inside of here, we are going to need to get an argument from our user when we run our program.
So we will say let adder equals standard environment args dot int.
And then expect.
So if they don't provide us.
Any arguments we expect address and port so at or is going to be our address and port so now we can
say task and then we want to block on.
And now we're going to create an async code block.
And we do this because we have asynchronous functions that we are going to call throughout our program.
So we need to wrap it inside of an async code block.
And now we want to establish our connection and then run the send and message functions defined up here.
At the same time.
So we'll start establishing our connection.
So we'll say let's socket equals net TCP stream, and then we want to connect on the adder.
So the address that we received from our user and we want to await and now we're going to say socket
set node lay to true
and node laid.
Is going to basically allow our stream to send tiny amounts of data.
Instead of waiting for X amount of data before sending anything.
So it allows us to send small amounts of data.
So we'll say let's send equals send.
So calling our send function socket clone because up here we needed a TCP stream which we created as
with our socket variable.
And now we're going to also call messages.
So we'll say messages.
On socket as well.
So now we want to exit as soon as either send or replies is completed so we can use a method called
race to complete this.
But in order for us to do this, we need to set async standard to unstable in our cargo tamil file,
which I've already done.
But essentially we do what we did for Tokyo and Saturday and we just set our features and then we.
Pull in the unstable features from that crate.
So now we can say replies dot race send.
Dot, await.
And race is going to wait for one of these two futures to finish.
And now to get rid of these squiggles, we will say, okay and we will end.
So we see we have a couple of.
Kurds.
Oh.
Wrong place.
That.
So race is going to wait for a future to return, is ready, and then whichever one returns is ready
first gets used and the other future is dropped.
So if send.
Finishes first, then this is dropped and we continue on with the send information that we received
and then it also works in the vice versa.
And so now we have some logic done inside our client's main function.
So now we can begin moving on to setting up the logic for our server.