1 00:00:05,870 --> 00:00:10,610 Before we continue, I realized that I forgot to do just a couple of things. 2 00:00:10,610 --> 00:00:18,000 So I want to make sure that we're all squared away before we continue on in libraries. 3 00:00:18,470 --> 00:00:22,160 We need to add this line to our server as well. 4 00:00:23,720 --> 00:00:30,740 And then inside of client, we need to add in use chat server client. 5 00:00:30,740 --> 00:00:37,580 That way we can reference our enum types, client and server. 6 00:00:38,210 --> 00:00:43,430 And then we also want to bring in use standard sync arc. 7 00:00:45,740 --> 00:00:52,880 And so once we have that, now we have enough implemented to allow us to create our main function inside 8 00:00:52,880 --> 00:00:53,780 of our client. 9 00:00:53,930 --> 00:00:58,130 So the first thing that we want to do is actually bring in another import. 10 00:00:58,130 --> 00:01:04,520 So we want to bring in async standard and then task. 11 00:01:06,630 --> 00:01:15,630 And now we can start implementing in our main function, which is going to return a chat result. 12 00:01:17,850 --> 00:01:27,480 And inside of here, we are going to need to get an argument from our user when we run our program. 13 00:01:27,720 --> 00:01:38,040 So we will say let adder equals standard environment args dot int. 14 00:01:40,670 --> 00:01:42,320 And then expect. 15 00:01:42,320 --> 00:01:44,660 So if they don't provide us. 16 00:01:46,400 --> 00:01:57,110 Any arguments we expect address and port so at or is going to be our address and port so now we can 17 00:01:57,110 --> 00:02:02,060 say task and then we want to block on. 18 00:02:04,750 --> 00:02:08,170 And now we're going to create an async code block. 19 00:02:08,320 --> 00:02:13,960 And we do this because we have asynchronous functions that we are going to call throughout our program. 20 00:02:14,470 --> 00:02:20,380 So we need to wrap it inside of an async code block. 21 00:02:21,360 --> 00:02:29,700 And now we want to establish our connection and then run the send and message functions defined up here. 22 00:02:31,690 --> 00:02:32,950 At the same time. 23 00:02:33,190 --> 00:02:35,710 So we'll start establishing our connection. 24 00:02:35,710 --> 00:02:45,220 So we'll say let's socket equals net TCP stream, and then we want to connect on the adder. 25 00:02:45,220 --> 00:02:53,590 So the address that we received from our user and we want to await and now we're going to say socket 26 00:02:53,590 --> 00:02:56,830 set node lay to true 27 00:02:59,920 --> 00:03:01,720 and node laid. 28 00:03:03,050 --> 00:03:10,190 Is going to basically allow our stream to send tiny amounts of data. 29 00:03:10,760 --> 00:03:15,110 Instead of waiting for X amount of data before sending anything. 30 00:03:15,110 --> 00:03:17,750 So it allows us to send small amounts of data. 31 00:03:18,320 --> 00:03:21,170 So we'll say let's send equals send. 32 00:03:21,170 --> 00:03:31,160 So calling our send function socket clone because up here we needed a TCP stream which we created as 33 00:03:31,310 --> 00:03:32,900 with our socket variable. 34 00:03:35,320 --> 00:03:37,960 And now we're going to also call messages. 35 00:03:37,960 --> 00:03:39,640 So we'll say messages. 36 00:03:41,790 --> 00:03:44,130 On socket as well. 37 00:03:45,750 --> 00:03:54,480 So now we want to exit as soon as either send or replies is completed so we can use a method called 38 00:03:54,480 --> 00:03:56,760 race to complete this. 39 00:03:56,760 --> 00:04:03,840 But in order for us to do this, we need to set async standard to unstable in our cargo tamil file, 40 00:04:03,990 --> 00:04:05,460 which I've already done. 41 00:04:07,250 --> 00:04:13,190 But essentially we do what we did for Tokyo and Saturday and we just set our features and then we. 42 00:04:13,950 --> 00:04:17,550 Pull in the unstable features from that crate. 43 00:04:18,480 --> 00:04:25,650 So now we can say replies dot race send. 44 00:04:25,890 --> 00:04:28,170 Dot, await. 45 00:04:31,180 --> 00:04:39,850 And race is going to wait for one of these two futures to finish. 46 00:04:41,580 --> 00:04:48,390 And now to get rid of these squiggles, we will say, okay and we will end. 47 00:04:51,890 --> 00:04:54,020 So we see we have a couple of. 48 00:04:57,230 --> 00:04:58,770 Kurds. 49 00:04:59,030 --> 00:04:59,420 Oh. 50 00:05:01,850 --> 00:05:03,050 Wrong place. 51 00:05:06,710 --> 00:05:06,870 That. 52 00:05:07,610 --> 00:05:16,370 So race is going to wait for a future to return, is ready, and then whichever one returns is ready 53 00:05:16,370 --> 00:05:20,010 first gets used and the other future is dropped. 54 00:05:20,030 --> 00:05:21,290 So if send. 55 00:05:22,220 --> 00:05:30,770 Finishes first, then this is dropped and we continue on with the send information that we received 56 00:05:30,770 --> 00:05:33,410 and then it also works in the vice versa. 57 00:05:35,130 --> 00:05:39,990 And so now we have some logic done inside our client's main function. 58 00:05:40,170 --> 00:05:45,480 So now we can begin moving on to setting up the logic for our server.