A distributed messaging system where clients (publishers) send messages to a central server, which then forwards those messages only to clients that have subscribed to that topic. This decouples senders from receivers — publishers don't need to know who is listening.
server.py- central message broker that tracks subscriptions and relays messagesclient.py- node that can subscribe to topics and publish messages
Open 4 terminals:
# Terminal 1 - start the server
cd publisher_subscriber_system
python3 server.py
# Terminal 2
cd publisher_subscriber_system
python3 client.py alice
# Terminal 3
cd publisher_subscriber_system
python3 client.py bob
# Terminal 4
cd publisher_subscriber_system
python3 client.py charlieInside any client:
sub TOPIC- subscribe to a topicpub TOPIC MESSAGE- publish a message to a topicquit- exit
alice> sub weather
bob> sub weather
alice> pub weather "sunny today"
Bob receives the message. Charlie (not subscribed to weather) does not.
- Server listens for connections
- Clients subscribe to topics
- Clients publish messages
- Server relays only to current subscribers
- At least 4 nodes tested
- No cloud storage, no data persistence on server