This project implements a basic TCP chat server and client using Python's socket and threading modules. The server accepts multiple client connections, allows clients to send messages to each other, and broadcasts messages to all connected clients.
This is a simple chat application with two main components:
- Server: The server listens for incoming client connections and handles the broadcasting of messages between clients.
- Client: The client connects to the server, sends messages, and listens for incoming messages from other clients.
Messages are encoded using base64 to prevent issues with transmitting non-text data.
To run the server and client, you'll need Python installed on your machine.
- Python 3.x
- No external libraries required (uses built-in libraries:
socket,threading,base64)
git clone <repository-url>cd <project-folder>You can check this by running the following:
python --version- To start the server, run the
server.pyfile:
python server.pyThe server will start listening on IP 127.0.0.1 (localhost) and port 4545.
- When clients connect, the server will print the client's address and a message about their username.
- Run the
client.pyfile to start the client.
python client.py-
The client will prompt you to enter a username, and then it will connect to the server. Once connected, you can start sending and receiving messages.
-
The client interface allows you to type messages, which will be broadcast to all connected clients.
127.0.0.1 made a pact with the devil and sold their soul!!!
Username is Alice
Alice joined!
> What would you like being called : Alice
> Alice: Hello, world!
> Alice: How's everyone doing?
To exit the chat, simply close the client window or press Ctrl + C in the terminal where the server is running. The server will automatically remove disconnected clients and broadcast the event to all other clients.
- Multiple Clients: The server supports multiple client connections at once.
- Message Broadcasting: All messages sent by clients are broadcast to all other clients connected to the server.
- Base64 Encoding: Messages are base64-encoded for transmission, ensuring compatibility with non-text data.
- Client Identification: Each client must provide a username upon connection.
This project is open-source and free to use under the MIT license. See the LICENSE file for more details.