EN
This is a chat application based on sockets designed to enable real-time communication between multiple clients connected to a central server. It uses threading in Python to handle simultaneous connections.
This is a real-time chat application that allows:
- Multiple clients to connect to a server.
- Messages to be exchanged between connected clients.
- Each client connection to be managed in a separate thread for seamless communication.
The goal of this application is to demonstrate how to use Python's built-in socket
and threading
libraries to build a simple and functional networking solution. It is ideal for learning basic concepts of networking and concurrency in Python.
-
Server:
- Listens for incoming connections on a specific IP address and port.
- Manages each client in a separate thread to allow multiple simultaneous connections.
- Broadcasts messages sent by one client to all other connected clients.
-
Client:
- Connects to the server by specifying its IP address and port.
- Sends a nickname to identify the user.
- Allows real-time message sending and receiving.
- Python 3.8 or higher installed on your system.
- Network connection to enable communication between the server and clients.
- Clone this repository to your local machine:
git clone https://github.com/yourusername/your-repository.git
- Open a terminal
- Navigate to the project directory:
cd your-repository
- Run the program in sever mode.
python app.py
- You will see the message:
[SERVER] Waiting for connections on 0.0.0.0:5555 This indicates the server is ready to accept connections.
- Open another terminal (you can use the same device or another device on the same network).
- Run the program in client mode:
python app.py
- Select the client options:
Select mode: 1. Server 2. Client Option: 2
- Enter the server's IP address when prompted:
Enter server IP: <SERVER_IP>
- Enter a nickname to identify yourself:
Enter your nickname: <YOUR_NICKNAME>
- Start chatting by typing messages in the terminal. Messages will be broadcast to all connected clients.
Type exit
in the client to disconnect from the server.
- Server running:
[SERVER] Waiting for connections on 0.0.0.0:5555 [NEW CLIENT] Connected from ('192.168.0.10', 54321)
- Messages exchanged between clients:
- Client 1:
[nickname1] Hello, how are you?
- Client 2:
[nickname1] Hello, how are you?
- Client 1:
- ConnectionRefusedError:
- Make sure the server is running before trying to connect as a client.
- TimeoutError:
- Verify that the server IP address is correct.
- Ensure both devices are on the same network.
- Unexpected disconnection:
- if a client disconnects abruptly, the server will remove the connection and allow others to continue functioning.
- This code does not implement encryption, meaning messages are sent in plain thext. ###Do not use it on public networks or production enviroments.###
- Consider implementing SSL/TLS for secure communication if deploying in a more serious context.
This project is licensed under the MIT License. You can use, modify, and distribute the code under the terms of this license.
Thank you for exploring this chat application! 💬 If you have suggestions or improvements, feel free to contribute to the project. 🚀
ES
Esta es una aplicación de chat basada en sockets diseñada para permitir la comunicación en tiempo real entre múltiples clientes conectados a un servidor central. Utiliza threading en Python para manejar múltiples conexiones simultáneamente.
Es una aplicación de chat en tiempo real que permite:
- Conectar múltiples clientes a un servidor.
- Intercambiar mensajes entre los clientes conectados.
- Gestionar cada conexión de cliente en un hilo separado para garantizar la fluidez de las comunicaciones.
Esta aplicación tiene como objetivo demostrar cómo se pueden usar las bibliotecas integradas de Python, como socket
y threading
, para construir una solución de red simple y funcional. Es ideal para aprender conceptos básicos de redes y concurrencia en Python.
-
Servidor:
- Escucha conexiones entrantes en una dirección IP y puerto específicos.
- Maneja cada cliente en un hilo independiente para permitir múltiples conexiones simultáneas.
- Difunde los mensajes enviados por un cliente a todos los demás clientes conectados.
-
Cliente:
- Se conecta al servidor especificando su IP y puerto.
- Envía un nickname para identificar al usuario.
- Permite enviar y recibir mensajes en tiempo real.
- Python 3.8 o superior instalado en tu sistema.
- Conexión de red para comunicación entre servidor y clientes.
- Clona este repositorio en tu máquina local:
git clone https://github.com/tuusuario/tu-repositorio.git
- Abre una terminal.
- Ejecuta el programa en modo servidor:
cd your-repository
- Ejecuta el programa en modo servidor:
python app.py
- Verás el siguiente mensaje:
[SERVER] Waiting for connections on 0.0.0.0:5555 Esto indica que el servidor está listo para aceptar conexiones.
- Abre otra terminal (puedes usar el mismo dispositivo o uno en la misma red).
- Ejecuta el programa en modo cliente:
python app.py
- Selecciona la opción de cliente:
Select mode: 1. Server 2. Client Option: 2
- Ingresa la dirección IP del servidor cuando se te solicite:
Enter server IP: <SERVER_IP>
- Ingresa un apodo para identificarte:
Enter your nickname: <YOUR_NICKNAME>
- Comienza a chatear escribiendo mensajes en la terminal. Los mensajes se enviarán a todos los clientes conectados.
Escribe exit
en el cliente para desconectarte del servidor.
- Servidor en ejecución:
[SERVER] Waiting for connections on 0.0.0.0:5555 [NEW CLIENT] Connected from ('192.168.0.10', 54321)
- Mensajes intercabiados entre clientes:
- Cliente 1:
[nickname1] Hello, how are you?
- Cliente 2:
[nickname1] Hello, how are you?
- Cliente 1:
- ConnectionRefusedError:
- Asegúrate de que el servidor esté corriendo antes de conectarte como cliente.
- TimeoutError:
- Verifica que la IP del servidor sea correcta.
- Asegúrate de que ambos dispositivos estén en la misma red.
- Desconexión inesperada:
- Si un cliente se desconecta abruptamente, el servidor eliminará la conexión y permitirá que otros sigan funcionando.
- Este código no implementa cifrado, lo que signidica que los mensajes se envían en texto plano. ###No lo utilices en redes públicas o en entornos de producción.###
- Considera usar SSL/TSL para protefer la comunicación si deseas implementarlo en un entorno más serio.
Este proyecto está bajo la Licencia MIT. Puedes usar, modificar y distribuir el código bajo los términos de esta licencia.
¡Gracias por explirar esta aplicación de chat en consola! 💬 Si tienes alguna sugerencia o mejora, no dudes en contribuir al proyecto. 🚀