Hi there! Today we are going to create a UDP-based chat application in python. This is a small task. The modules we are going to use in it are :
- Threading - for multithreading capabilities
- Socket - for socket programming
Let's start
For this practical, we need 2 machines and in this demo, I am using my windows machine and my one virtual machine running with Linux distro.
The above module should be installed on your system. To check this you can use
pip list
If you haven't installed these modules then you can install them using
pip install <module_name>
Now we will write our python script for the chat application. I have already written it which looks like this
We need to create the same files in both the system and put the respective IP in the code as said in it. Now all that's left is to test the code and see how it is working.
To run the code we use the command
python <filename>
As you can see it is working fine but if you observe carefully you will notice that some data hasn't been received by the machines which is the con of UDP protocol as it is unreliable in data transfer. Thus we use TCP instead of UDP in critical operations related to the data transfer
That's it for this one. It was a short one. See you next time... !!