-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
61 lines (53 loc) · 1.71 KB
/
client.py
File metadata and controls
61 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Import socket module
import socket
def Main():
# local host IP '127.0.0.1'
host = '127.0.0.1'
# Define the port on which you want to connect
port = 12345
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect to server on local computer
s.connect((host, port))
while True:
# ask options
ans = input('\nWhat would you like to do?'
'\n1: Check balance'
'\n2: Withdrawal'
'\n3: Deposit'
'\nq: End the current session\n: ')
# Check balance
if ans == '1':
s.send(ans.encode('ascii'))
data = s.recv(1024)
print('\nCurrent balance :', str(data, 'utf8'))
continue
# Withdraw
if ans == '2':
s.send(ans.encode('ascii'))
withdraw = input('\n How much to withdrawal? : ')
s.send(withdraw.encode('ascii'))
data = s.recv(1024)
if data == b'No':
print("\nNot enough funds.")
else:
print('\nBalance after withdrawal :', str(data, 'utf8'))
continue
# Deposit
if ans == '3':
s.send(ans.encode('ascii'))
deposit = input('\n How much to deposit? : ')
s.send(deposit.encode('ascii'))
data = s.recv(1024)
print('\nBalance after withdrawal :', str(data, 'utf8'))
continue
# Quits session
if ans == 'q':
print("\nEnding session")
break
else:
print("\nNot a valid input, try again.")
continue
# close the connection
s.close()
if __name__ == '__main__':
Main()