Hello and welcome to the golden programming language course in the petrol station, we talked about
VIPs to get concept.
Now it's time to do a project in this session.
In this section, we want to implement a simple chat program using bits to get technology.
We designed the program in such a way that any client that sends the message to the server and the other
clients can see that message.
Now let's go to a school program to implement this project.
This program consists of three different layers socket, client and server.
First, go to Package Explorer and go to the Sazi folder and create a project folder named like Web
Sujit with Sujit for this purpose.
First, download Let's at package from Go.
Let that go.
So go to Terminal.
Go to the project folder.
Let's look at.
Now, execute the following comment Go get the you go blank.
Dot org slash eats explosion.
That's that's that's the secret.
OK, installation has completed first.
We will implement the circuit layer.
So go to Project Folder and create a folder name like circuit.
And create a foreign name like socket that go inside its
socket that will set the package name package.
So it.
This file maintains the set of active connections and broadcast messages to the connections.
These connections are mapped from a string array of connections creating different rooms.
Server sends data to client and client gets data and this serialized it.
Then we create a structure that whole channels for communication between client and server and then
create run method for run configurations.
The communication data between the client and the server in this example is created by Jason.
So first, we create a strength for the transmission message.
For example, we create a struct name, message, time, message extract.
Define the field like subject by the type string and using JSON tag for it.
Subject.
By the time a string and said Jason.
Pack for it, Jason.
Column double quotation mark and set value for its object.
Now we create a separate channel for each of the actions in the chats, for example, to add a client
or delete a client or send the message by a client.
We create a separate channel and put them inside, distract.
So defining the strike named like can ft tie config extract.
Now define global variable.
First, clients feel that is the least of all clients, the active clients or open with its clients
and type of this client is a map by entering for key man.
And key type is strange and vets connection as a value that restores the client connection point of
VIPs who get.
That connection.
Now defined channels for different operations and chat, for example, for at a client, the right defined
and variable like register clients and defined their channel channel by the time web socket.
That connection,
and for him, all the client, be right.
Remove client Chan by the time I point out the kids.
That connection and for exchange messages, he writes, for example, message data channel.
By the time message extract message data is a single channel that is responsible for sending and receiving
our message data structure.
In order to be able to initialize the created channels, we create a constructor and initialize them,
so define the function like named new config.
So we write find new config and return type is a pointer of config.
Extract pointer our config extract.
The job of this function is to give basic information to the config extract.
So return a pointer of config, extract and create a map for clients and create channels for other fields.
So the right return ampersand config.
Now, invoking each conflict, Phyllis, right, then initialized them clients
create a map for this field by make function make.
My
type of key is strong and type of values, --, introvert, secure connection.
Pointed out that Richard Nixon.
Registered clients
create a channel for registered clients and by calling make function, all right, make.
Chan and points are a bit to get of conviction and for removal, and
again, the calling make function.
Make Chan points of work to get conviction and for message data,
create a channel for message data from the messages to solve right.
Make Chan off message in order not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.