Introduction • Implementation • Example • Installation • Author • Support
This Server & Client code is the final product of computer-networks course assignment, which I took in the 1st semester of my 2nd year at Bar Ilan University.
I implemeted code which acts like WhatsApp-groups, in where each user (client) can:
💥 Join the group
💥 Send messages to all other members of the group.
💥 Change his name for future messages
💥 Get notifications about other people's activity in the group- when someone else has joined, sent a message, left the group, etc.
Our chat will act similar to a Whatsapp group, in which each member can write a message, and every message someone writes is sent to all other memebers.
When someone is sending a message, the message is being sent to the server immediately. Yet, the server sents the message to the other memebers only when they reach out the server.
For example: Alice, Bob, and Charlie are members in the group. Alice sent a message. The message needs to be sent to Bob and Charlie,
but they will receive Alice's message only when they ask for it explicitly from the server, or if they will send a message to the server so he will send them back all their waiting messages.
Our server is establishing a socket and listens on the port number which he receives as an argument from CLI.
The server can receive 5 different types of messages:
-
Register- Client which sends this message, wants to join the group chat.
The message will be in the following format: 1 [Name]The server keeps details of the client's name and socket details, and sends all other members the message: [Name] has joined.
Also, the server sends to the client who asked to join all names of the existing members in the group. -
Sending a message- Client wants to send a message to all other members in the group.
The message will be in the following format: 1 [Name]: [Message] -
Change of name- Client which sends this message, wants to change his name in the group.
The message will be in the following format: 3 [Name]When the server recieves this type of message, it sends all other members the message:
[Old Name] changed his name to [New Name]. -
leaving the group- Client which sends this message, wants to leave the group.
The message will be in the following format: 4When the server recieves this type of message, it sends all other members the message: [Name] has left the group.
-
Get new info- Client which sends this message, wants to get notification abut all new messages since his last update.
The message will be in the following format: 5When the server recieves this type of message, it sends the client 1 message that contain all the messages
that were supposed to be sent to him since the last time.
2. Bob registered.
3. Bob sent a message.
4. Display so far:
5. Charlie registered.
6. Charlie sent 2 messages.
7. Display so far:
8. Alice asked for update.
9. Display so far:
10. Alice sent a message.
11. Alice sent invalid message.
12. Charlie changed his name.
13. Charlie sent a message.
14. Display so far:
15. Charlie left.
16. Bob sent a message.
17. Alice asked for update.
18. Display so far:
-
Clone this repo by creating a specific folder in your computer, open terminal in this folder and run this command:
git clone https://github.com/TopazAvraham/ChatApp--Multiple-Clients-to-Server-UDP-Sockets
Alternatively, you can just download all the files from this repo to your computer, and save them all in that specific folder
-
Open different “terminals” in this specific folder.
-
Run this command in one terminal to run the server code:
python3 server.py (para1)
where para1 = port number that the server will listen to.
- Run this command in a second terminal to run the client code:
python3 client.py (para1) (para2)
where para1 = IP address of the server
and para2 = Port number of the server
-
You can also open as many terminals as you wish to illustrate different clients.
-
Start chatting in the group and enjoy the results.
- Python
- UDP Sockets
Topaz Avraham
Contributions, issues, and feature requests are welcome!
Give a ⭐️ if you like this project!