Creating Chat Servers using Socket Programming in Python
Vivek Sharma
RedHat Certified in Containers and Kubernetes(EX180) ||Arth || Aspiring DevOps Engineer || Python || Docker || Ansible || Jenkins || Kubernetes || OpenShift || Terraform || GitHub || AWS || AZURE
ARTH - Task 17 ??????
?? Create your own Chat Servers, and establish a network to transfer data using Socket Programing by creating both Server and Client machine as Sender and Receiver both. Do this program using UDP data transfer protocol.
?? Use multi-threading concept to get and receive data parallelly from both the Server Sides. Observe the challenges that you face to achieve this using UDP.?
What is Socket Programming in Python ?
Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the other to form a connection. The server forms the listener socket while the client reaches out to the server.
What is UDP Data Transfer Protocol ?
User Datagram Protocol (UDP) is a communications protocol that facilitates the exchange of messages between computing devices in a network.
UDP divides messages into packets, called datagrams, which can then be forwarded by the devices in the network – switches, routers, security gateways – to the destination application/server. While UDP does not number or reassemble the datagrams, it does include port numbers in the datagram header that help distinguish different user requests and an optional checksum capability that can help verify the integrity of the data transferred.
What is Multi-threading in Python ?
Generally it is tendency of a program to execute it's statements one by one , so a statement is executed only when the statement or command prior to it has completed execution. Multi-threading is the ability of CPU to provide multi-threads to execute the program concurrently. Means if two commands are present in the program then they will be executed at the same time independently.
Let's begin with the Practical part -
To use socket and threading module one must install them. One can easily do that with the help pip3 python package installation command -
for socket module
# pip3 install sockets
for threading module
# pip3 install thread6
In this task I have used two nodes one is Windows 10 node and other is RedHat Linux node running in the same windows system as a virtual machine.
The code for both the nodes is same -
领英推荐
Explanation of the Code -
The Linux system also has the same code except for the host and sending IPs.
To start the chatting run both file at same time using Python3 command and start chatting -
# python3 <file_name>
The left command prompts is of windows localhost and the right one is of Linux VM.
Windows Prompt
Linux Prompt
Some Challenges faced while doing the Task --
THANK YOU FOR READING!!!!!!!!!!!!