In today's digital age, there is a growing need for secure and efficient communication systems that can handle multiple functionalities simultaneously. Specifically, there is a demand for systems that can provide synchronous chatting and video streaming capabilities over a reliable network protocol. The challenge is to create a robust application that ensures secure communication, real-time updates, and efficient handling of multiple client connections using TCP/IP, all while maintaining high performance and user experience.
This project addresses the problem by implementing a secured system for video streaming and messaging using Python, socket programming, TCP/IP, OpenCV, and multithreading. The application is designed to handle synchronous chatting and video streaming concurrently, enhancing the user experience with real-time communication and media capabilities.
- Secure Communication: Utilizes RSA encryption for secure messaging between clients.
- Concurrent Functionality: Implements multithreading to allow simultaneous video streaming and messaging.
- Real-Time Updates: Clients are updated on entry and exit, demonstrating proficiency in network architecture.
- Video Streaming: Allows clients to request and stream video files from the server.
- Robust Messaging: Facilitates real-time messaging between clients.
- Python 3.x
- OpenCV
- RSA
- Numpy
- Pandas
- Install the required libraries using pip:
pip install opencv-python rsa numpy pandas
- Start the server by running the following command:
python server.py
The server will start listening for incoming connections on the specified IP and port.
- Start the client by running the following command:
python client.py
- Enter your name when prompted. Choose to send a message or request a video stream.
- Importing Libraries
The client code imports necessary libraries such as socket, threading, json, time, rsa, cv2, and numpy.
- RSA Key Generation
The function generate_rsa_key_pair() is used to generate an RSA key pair for encryption and decryption of messages.
- Connect to Server
The function connect_to_server(name, public_key) establishes a connection to the server and sends the client's name and public key.
- Sending and Receiving Messages
send_message(client_socket) handles sending messages to selected clients. receive_messages(client_socket) handles receiving messages from the server.
- Video Streaming
request_video_list(client_socket) requests a list of available videos from the server. handle_video_stream(chunk_data) handles the video stream received from the server. play_video() plays the received video stream.
- Threading
send_requests(client_socket) runs in a separate thread to handle user inputs for sending messages or requesting videos. receive_messages(client_socket) runs in a separate thread to handle incoming messages from the server.
- Importing Libraries
The server code imports necessary libraries such as socket, threading, json, os, time, and cv2.
- Handling New Clients
The function handle_new_client(server_socket) handles new client connections and starts a new thread for each client.
- Sending and Receiving Messages
receive_messages(client_socket) handles incoming messages from clients. broadcast_message(message) broadcasts messages to all connected clients.
- Video Streaming
send_video_list(client_socket) sends the list of available videos to clients. handle_video_request(video_name, client_socket) handles video streaming to the requesting client.
- Main Function
The main() function initializes the server, binds it to the specified IP and port, and starts listening for incoming connections.