-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileSysClient.py
More file actions
44 lines (40 loc) · 1.18 KB
/
fileSysClient.py
File metadata and controls
44 lines (40 loc) · 1.18 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
import socket
import pickle
import time
ClientMultiSocket = socket.socket()
host = '127.0.0.1'
# host = '192.356.31.3'
port = 21018
attempts = 0
print('Waiting for connection response...\n')
while True:
try:
ClientMultiSocket.connect((host, port))
print('CONNECTED')
break
except socket.error as e:
attempts += 1
if (attempts > 4):
print('No response from server, try again later.')
exit(0)
print('Server is offline, trying again in 2 seconds...')
time.sleep(2)
res = ClientMultiSocket.recv(32768)
usernameInput = input('\nEnter your username: ')
ClientMultiSocket.send(str.encode(usernameInput))
print('Logged into filesystem with the username, ' + usernameInput + '\n')
print('>> ', end='')
while True:
Input = input()
ClientMultiSocket.send(str.encode(Input))
if(Input == 'exit'):
break
res = ClientMultiSocket.recv(32768)
res_data = pickle.loads(res)
if(res_data[0] == 'exit'):
print('\nServer Inaccessible: Request quota exceeded, try later.')
print('Bye!')
break
print('\n' + res_data[0])
print(res_data[1] + '>> ', end='')
ClientMultiSocket.close()