1 00:00:05,880 --> 00:00:09,330 So now we need to work on allowing us to send messages. 2 00:00:09,780 --> 00:00:17,520 So we're going to need to implement the function that we already called here called send JSON that our 3 00:00:17,520 --> 00:00:20,430 client and server are both going to use. 4 00:00:20,460 --> 00:00:26,970 So with client and server using the function, we are going to place it inside our utils file. 5 00:00:27,480 --> 00:00:32,730 So let's head over to our utils file and let's start adding in a couple of more use statements that 6 00:00:32,730 --> 00:00:33,570 we're going to need. 7 00:00:34,350 --> 00:00:37,020 So we have async standard. 8 00:00:37,020 --> 00:00:48,330 We want to add in everything in the prelude, we want to use serialize and then we want to use standard 9 00:00:48,330 --> 00:00:49,230 marker. 10 00:00:52,310 --> 00:00:54,200 UN pin. 11 00:00:57,430 --> 00:01:05,830 So the function we are going to create is going to create a JSON representation of our packet as a string. 12 00:01:06,460 --> 00:01:12,430 Then we will add a new line to the end of the string and write it all to leaving. 13 00:01:14,530 --> 00:01:18,550 So let's begin to set that up so that you all can see what I'm talking about. 14 00:01:18,550 --> 00:01:25,030 So we're going to say send JSON, we're going to have two generics O and P. 15 00:01:27,920 --> 00:01:34,910 So we're going to say leaving, which is going to be a mutable reference to our generic and then we're 16 00:01:34,910 --> 00:01:36,980 going to have a packet. 17 00:01:38,310 --> 00:01:46,200 Which is a reference to our p generic and we're returning a chat result. 18 00:01:47,070 --> 00:01:54,240 So we have a generico and p and now we can define define a couple of constraints on it. 19 00:01:54,630 --> 00:01:57,600 So we will need a where clause. 20 00:01:58,470 --> 00:02:06,780 So up here we will say where oh is async standard? 21 00:02:08,630 --> 00:02:09,020 I. 22 00:02:10,010 --> 00:02:10,900 Right. 23 00:02:11,210 --> 00:02:12,560 And unpin. 24 00:02:13,800 --> 00:02:17,970 And then p implements serialize. 25 00:02:18,120 --> 00:02:22,410 So let's cargo format that to make it look better. 26 00:02:23,530 --> 00:02:25,150 And there we go. 27 00:02:26,410 --> 00:02:34,450 So now we have our oh generic which must implement right and on pen and then our p generic which is 28 00:02:34,450 --> 00:02:36,970 must implement serialize. 29 00:02:37,390 --> 00:02:42,550 So now we can turn our packet to a string and then write it to our leaving. 30 00:02:44,950 --> 00:02:56,620 So we'll say let mutable JSON equals say or de json to string and do that with our. 31 00:02:58,030 --> 00:03:04,000 Packet and then we want to push in our new line character, as I said earlier. 32 00:03:08,500 --> 00:03:11,740 And now we're going to ride it to leaving. 33 00:03:15,350 --> 00:03:15,650 Right. 34 00:03:15,650 --> 00:03:21,380 All JSON as bytes. 35 00:03:22,570 --> 00:03:23,320 Dot. 36 00:03:24,640 --> 00:03:25,090 Wait. 37 00:03:27,600 --> 00:03:28,860 And now we want to. 38 00:03:29,740 --> 00:03:30,350 Return. 39 00:03:30,600 --> 00:03:37,150 Okay, so now we have our logic implemented for sending messages. 40 00:03:37,150 --> 00:03:42,400 So let's begin on working to receive these messages.