CHAT SERVER USING PYTHON SOCKET PROGRAMMING..
A warm welcome of you all, in this Article we gonna cover HOW TO MAKE OUR OWN CHAT SERVER USING PYTHON SOCKET PROGRAMMING..
First, let’s discuss about the Socket Programming.
Socket programming is a programming schema in which sockets are used and manipulated to create a connection between software. Sockets are used to connect software either between different computers or within the same computer so the programs can share data. Socket programming is used with instant messaging, Internet browsers, file sharing programs, and anything that forces the computer to connect to a system. Most sockets are programmed automatically, but some operating systems (OS) place this responsibility in the hands of the user.
Here, we are using Socket Programming of Python, to establish one Chat Server between two Operating System, using Sockets.
A network socket is a software structure within a network node of a computer network that serves as an endpoint for sending and receiving data across the network. The structure and properties of a socket are defined by an application programming interface for the networking architecture.
So, now let’s go deep dive into the Practical Part:-
TASK- We have to create our own Chat Servers, and wanna establish a network to transfer the data using Socket Programming by creating both the Servers and Client machine as Sender and Receiver. Using UDP data transfer Protocol.
STEP-1:- For doing this task I have taken two RED HAT 8 Linux OS, named as Server & Client respectively.
Two OS which have IP address 249 & 34 respectively.
STEP-2:- Check the connectivity between the both the OS, using ping command:-
So my both the OS has proper connectivity.
STEP-3:- Now, let’s create a Python code in Server OS for Establishing Chat Server:-
a)- First I loaded the Socket Module of Python for using Socket Programming.
b)- I have used AF_NET property of the socket module to tell my socket that I have to use IPv4 Family of IP. Because to establish socket, you have to tell that from which IP address Family your IP belongs.
c)- Then I have used SOCK_DGRAM property of the socket module to tell my socket that you have to use UDP protocol for transferring and collecting the data packets.
UDP Protocol:- A protocol who do not acknowledge back to the sending IP, that receiving OS has received the Data or not. It is known for Fast Transferring of Data.
d)- Telling the socket to use this Protocol and IP family.
e)- Binding my OS IP and unique number(PORT NUMBER), to create a socket.
f)- Then I have created an RECV function in Python, for receiving the data and used the recvfrom() function of socket module to take the input from the client OS.
g)- Created SEND function in Python, for sending the data and used the sendto() function of socket module to send the message to the Client.
STEP-4:- Same code I have created in my client OS also, with different PORT NUMBER, code:-
STEP-5:- Now, we just have to run the program in both the OS.Command:-
As you run the program, you will see one port number start running with your socket, command:
And now you see you can easily chat like these:-
GIT HUB LINK:-
Contribute to Sarvjeet-Jain/CHAT-SERVER development by creating an account on GitHub.
URRAY FINALLY WE HAVE CREATED OUR OWN CHAT SERVER…
THANK YOU FOR READING THIS ARTICLE…