Video Chat app using Python Socket programming

Yash Agarwal
4 min readJun 16, 2021

In this pandemic, we are experiencing a huge number of the company moving towards the online platform and started the great initiative work from home but how it is possible if we cant connect with the team.

So to solve this challenge company start using software that allows them to connect virtually with the help of a camera and other resources, but have you ever wondered how these things work behind the scene.

In this article, I will create a socket program code for the client and the server so that client can easily connect with the server using the Ip address and port number of the server. We will be doing everything using python OpenCV and socket programming concepts.

We are going to use the OpenCV python library which gives us support to access our device camera so if you are not familiar with it you can refer to my previous article here.

So what is Socket?

A socket is just a networking interface that helps to connect 2 devices or networking by binding the IP address and the port number on which the service is going to be run.

So let us start with the creation of a socket for server-side

Here first we imported the socket module and then passed 2 parameters which are AF_NET which refers that we are going to use the Ip address from the network family of IPv4 and the second one is SOCK_STREAM which is used to make a connection over TCP protocol.

Here we can use UDP also but TCP is more reliable as it provides the confirmation that the packet is successfully received on the other end of the connection and if not then it will again send it.

Here I have bound my system IP address with some random port as for the client to connect it needs two things my IP address and port number, now I am declaring that my program will run on this port and if any client wants to connect it on this port number.

After this, If the server gets any request from the client then it will start the process to capture the photo and for sending video or photos we just have used the concept is OpenCV which will click a photo from the device and send it to the client but it is so much fast it can appear as a video as video is also made from continues capturing of the photo.

This is the server-side program for the video chat app now we will look into the client-side program and what changes we have to perform in it.

Here we can observe instead of a bind we have used connect keyword as the client will connect the server using ita IP address and port number of the server on which the service is running.

In this also we used OpenCV to send and receive a photo from the server and we have used imshow to display the video frame that is going to be captured.

Now for running server code we just have to use the command

Now as we run it won't do anything as it is waiting for the client to connect to the server and let's run the client code.

Now as run this command our camera will start and it will send the photo to the server and receive it as well.

We can see that one stream is from the server and the other is from the client-side and our program is working fine.

Here is the Github link to the program file.

Conclusion:

We can see it is easy that easy to make our own meeting app if know the right concept behind it, the above app-only display video not audio but now we can extend this very easily if we have made this much.

Thank you for reading this article !!

--

--