Hi everyone.
In this video we will answer some questions in your head.
Now you may ask me right here if you see in the WebSocket server we have a WebSocket.
And inside the callback over here we only interact with the socket callback over here.
But why the script right here?
It doesn't have anything like socket or something like that okay.
Why does it have and why it interact directly into the socket over here okay.
And why we not to interact the directly with the WebSocket over here.
Why?
Okay.
I know it very confusing at the beginning Because that's my story.
Okay.
When the first time I learned, I will ask the question why?
Like this?
And in this video, let me answer the question.
Okay.
Firstly, you can see when we establish a WebSocket we will got the socket.
Okay.
So what exactly about socket.
The socket right here is a endpoint between the client and server okay.
For example, from the computer A, if we want to send data into the computer B okay, we.
The computer a a also have some port.
For example like this arrow here is a client okay.
And the client.
Maybe it will a random part and B right here in a server.
Maybe it will have a 3000.
Okay.
And in order to send using the WebSocket over here, we will create the socket okay.
Okay.
The socket endpoint between the.
Client and specific server.
Okay.
Now the first thing I want to show you is what it is socket.
And you can see one server, it might be.
Have so many clients okay.
It have so many clients.
But you can see one client only have one server, okay.
Okay, so that's in a relationship right now.
The one to many relationship between the server and client.
One server can have multiple clients, but many clients only have one server.
Okay.
Notice about that.
So for that reason in this case we don't have anything like WebSockets in the client side.
Because by the end of day, the client over here is only have one server okay.
It doesn't have another server.
For that reason.
We don't need anything like socket over here.
But the server is a different story.
Because.
Once server can have multiples clients, for that reason, we need the WebSockets right here to know
the specific client.
Okay.
It will with the WebSocket over here, it will identify what exactly the client connect to the server.
For example inside here inside here this is the one client right.
This one client.
And if I duplicate you can see I will connect.
It will connect okay.
And one more thing it will connect one more thing okay.
So that is that's about the relationship.
And from now I hope you already understand.
Okay let me summarize, the socket right here is only belong to the specific server
for a reason.
It doesn't need anything like WebSocket inside the callback, and it will interact back to the server
using directly socket.
Okay, because from here we clearly know this only connects to that server.
Okay.
And with the server connection right here, we have a callback because with the socket inside callback
over here we will know what Specificed client try to connect to the server.
So I hope you are clear right now.
I will see you in the next.