Python Answers Only Create a client code and a server code i

Python Answers Only!!!!

Create a client code and a server code, in Python, for an ATM machine that can print a list of items that interacts with the client on the following:

1. Withdrawal
2. Deposit
3. Check the account

Solution

Below are the skeleton for the server and the client python files, they are almost complete excpet for the Withdrawal,Deposit and Check account code, To implement the required functionality you can use the single variable that is share between both Client and the Server which saves the current account balance.
Each time the user withdraws the money or deposits the money the specified money is either added or deducted from the account balance.
Use the send() and recv() functions to send and recieve the data between the client and the server.Remember the data sent between the Client and ther Server is in Byte for (b).

#!/usr/bin/python # This is server.py file

import socket # Import socket module

s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port

s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print (\'Got connection from\',addr)
data = c.recv(1024)
if(data == b\'4\'): exit()
else if(data == b\'3\'): #write your code to print account details print(AccBal)
else if(data == b\'2\'): #write your code to deposit money
else if(data == b\'1\'): #write your code to withdraw money
c.send(bytes(\'Thank you for connecting\',\'utf8\'))
c.close() # Close the connection

#!/usr/bin/python # This is client.py file

import socket # Import socket module

s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.

s.connect((host, port))
x = input(\'Enter your choice \ 1. Withdrawal\ 2. Deposit\ 3. Check the account\ 4. Exit\');
s.send(bytes(x,\'utf8\'));
print (s.recv(1024))
s.close # Close the socket when done

Python Answers Only!!!! Create a client code and a server code, in Python, for an ATM machine that can print a list of items that interacts with the client on t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site