ex_4
ex_4
: 4
Client-Server Model:
1. Server:
It waits for incoming connections from clients and handles their requests.
• Once a connection is established, the server processes client
Code:
Socket Server Model Code(server.py)
class SimpleServer(protocol.Protocol):
def connectionMade(self):
message = data.decode().strip()
self.transport.write(response.encode())
def connectionLost(self, reason):
class SimpleFacory(protocol.Factory):
port = 8888
reactor.run()
class SimpleClient(protocol.Protocol):
def connectionMade(self):
print(f"[SERVER] {data.decode().strip()}")
def send_data(self):
if msg.lower() == 'exit':
print("[INFO] Closing connection...")
reactor.stop()
break
self.transport.write(msg.encode())
class SimpleClientFactory(protocol.ClientFactory):
reactor.stop()
reactor.run()
Output:
On client side:
On server side:
RESULT:
Thus the Client Server Architecture is implemented in twisted python and a report for the
model architecture is prepared.