 a version of very basic features of OTP and how can you use it to connect between different nodes in your network. So this is an extremely basic application that what it does it just starts a GenServer. GenServer is basically a process that keeps some state. So it goes in the loop and every next loop it goes you can update the state. So here if I do something like this message, it will add this message that I sent to the list of all messages, right? So it means that it will not provide any reply, I will not get any reply, but the next loop will be run with this state. And when I indeed it, it gives my, it gives, okay, and the first state that it starts is an empty list. And then if I handle a code with the text get messages, it will return all messages, like this is reply, this is the content of the reply, and this is the last one is the state that it will go with in the next loop, so you can do it. Okay, so I need to start this server, stock server, start link. Now this is the PID of this server, and I need to pass this PID. So right now let me assign it to some variable, so now this PID is all 0.15.0, and now I can do server send message, I provide the PID and I do server get messages, I need to provide this PID. And I got this message, right, so 2 and now 3, and I've got all these messages here. So that's extremely basic version, but it's also very convenient, right, because you have to provide this PID, you have to get it and pass it around. So now the next version that we will do is, let's get the second code. And now what we have is that, you see there is a difference here, I provide the name, so I provide the name of this process, it will be called TOG, and now when I send message, I provide this TOG here, so let's see how it will work. So once again I need to start server and I got the PID, but I do not need it anymore, because whatever we do, it will be just a send message. Okay, so this is good, so we already got rid of this PID that we need to pass around, but now the problem that we have is what happens in this process dies. So I can do the process where it's, the name of the process is TOG, I've got this process here, and now what I do, I will do the process kill, exit kill, and now it's process died. So now if I do good messages, I don't have it because that process died. So now the next thing that we can do is, is we can add the supervisor. So this, the change to go now, this find it in change, but what we added here is a supervisor. And the supervisor where we started it, it starts a process that will be called top master, and this process will have one worker that will be the server, and it will supervise it with strategy called one for one. Which means that whenever a single process dies, the supervisor will restart that very same process. So let's see how it works here. So now instead of the gen server, we will start the supervisor, and we got it, it has the PID here, now what we will do is stock server, some messages, it works, now we will do the messages, it works, now we will kill the process, it killed it, and now when we send message, we can send it again, because that process, because we started by the supervisor. The only problem here is that it contains only one message, because when we lost that previous process, we lost everything that it contained, we lost it's state. So the solution to that is to use the ETS that called showdice, that can be, when the process that holds the ETS is killed, the ETS, the content can be passed to the supervisor and the supervisor can give it back to the next process it starts. Okay, a few more things that show is, okay, so I'm going to add the archive module to show you another strategy. So this archive, Joe, what it will do, it will be containing all the messages, it will contain all the messages that our server contains. So server, when it gets a message, it will just pass it to archive. So the server dies, server is restarted, but the archive still contains all these messages, right? So right now our supervisor has both server and archive. Yeah, sure. It's basically the same as the server. It's like a copy, the only difference is that server passes the message to archive. So the archive, it's pretty useless, right? It's just another process that keeps the same information. They just want to use it to show you this other strategy. So we start supervisor, so I've got this message and archive gets the same message as server. And now if we kill the process where is talk, so the server died. So server has no messages, archive gets messages because archive survived. And now we will change the strategy to one for all. The only difference that I introduced here is the strategy. It was one for one, now it's one for all. One for all is that if one process dies, all the processes are restarted. So let's talk supervisor start. We've got this message, archive gets this message, now process. And now we killed both of these processes. So if you check now, archive doesn't get any message because it was restarted as well. So if you have situation where the processes depend on each other and one of them dies and changes its state, you need to restart all the other process as well, then you will use this strategy. In my case obviously it was completely useless because I just removed the archive that is supposed to survive when my process dies. There are two more strategies but I didn't dig deep into them, so we need to check in the documentation. One is called simple one for one and the other one rest for one or something like this. I do not really remember. Simple one for one. Exactly. They are going to introduce them dynamically. And that's basically going to represent the simple one for one strategy. And dynamic supervisors are there just to allow you to dynamically create new workers within a supervisor. And that's what a simple one for one actually represents. Okay, so it's not really simplified version of what we're talking about. Okay, so it's just the wrong timing. Workers as in they are all the same module. It's one for one when they are different. Kind of like full of workers, right? Yes, exactly. Okay, what I did now in this next comment is I introduced the application. So when I created the project I had this application, let's talk this module and it was like this. And now I extend it so that I start this module. And whenever I start the application, whenever I enter it, it will just create the supervisor automatically for me. And to do it I also needed to add it here to the mix file. So this mod says what is the module of my application. So I said that the module of my application is let's talk. Which means that whenever I start, I do the command to run mix run. This module will be invoked and it will call the method start. So right now if I do mix, it already started. So I can just do let's talk, server, send message. And it already works. I don't need to create the supervisor. It's done automatically for me. So now what I want to show you, let's see if something else changed here. No, everything here stays the same. So now what I'm going to do is I'm going to connect two different nodes with each other. And to that I will need my last commit. Should use global process name. So just to make it clear. So this process here, it's a local process. I cannot find it on another nodes. Even if I connect my nodes in a network, this process it's only available to this single machine. Because I log, I register it in like a local registry. So now we will use the feature that allows us to use the process, the same single process from various nodes in network. What? What is this git platform you're using? Or is this one? G. Ah yes, so it's git. Yes. Because I call it so often that I just single it. Okay, now. So I'm going to use a global process name. So what I do here is when I start my gen server, I have this PID. And now I say that using this global module that also showed us before, I register this process ID under the name talk. And I'm registering it globally, which means that any node that connects to my node will have access to that. And then when I send messages, what I do is I find this PID and then I pass it to the gen server. And also what I did is that I do not start my application anymore. And I will show you, I will explain in a moment why. So what I'm going to do now is I X and I will call my mod n1. I will use the name of cookie. Start. Does it work? Yeah, okay. So what I did is I'm calling these, I'm running this application with two parameters. S name means short name, which means that it's the name of my node, short name of my node. And cookie is like, it's kind of like a message that if a few nodes use the same message, they will be able to discover each other. You can think of it as a password, but it's very insecure password because it's passed around in a plain text. So don't think about it as a security. It's most like, if you want to have a few networks, then you just use different identifier, right? And here I'm going to do the same. S name and two. Okay. So here you see I am node n1 at G is the name of my computer. So this is the name of the node and this is the name of the host. And now these nodes are not connected to each other. So I've got node.list and it's empty and the same here. Now I need to connect these nodes together. So what I do is node connect. And I pass an atom that will be the name of my computer and it returns true. Now we are connected. And now this process will start this node will start the supervisor. So let's supervisor start link. And now this process can get messages. It's empty. It can send message. And this process can do the same. It can get messages from the other node. This is just because I'm using this global name space here in my server. That's why they can communicate and they can easily find the process in the network. And now let's say that I'm, what? I'm not really sure if it's UDP or TCP. To be honest I have no idea. What's cool is that you don't need. Exactly. Okay. And now if I do, if I use different cookie here. And I call 175 and three. Okay. I started the application. And now I try to connect to node, connect. Once again it will be N2 and G. And it returns false. So this node, this is N2. It sees that someone tried to connect, but it couldn't because it didn't provide the correct identifier, right? So now I can't, obviously, I can't find that process. So let's get messages. I can't find it because I don't have access to that global process. So that global name space is available to the whole network, but to join the network you need to know the name. Know the name of the host that you want to connect with and the name of this identifier. And yeah, I think that's it. Just wanted to show that it's extremely easy to connect a few nodes. And you can do the same over the, over multiple computers. If you've got the local network, then you can do the same just by using either some host name or IP. Yeah, I think that's it. Thanks. Some more questions? No.