-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
74 lines (54 loc) · 1.56 KB
/
Client.py
File metadata and controls
74 lines (54 loc) · 1.56 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
62
63
64
65
66
67
68
69
70
71
72
73
74
import socket
VERSION = '0.08'
def get_choice(prompt):
return input(prompt)
def load_data_from_file():
file = open('client.data', 'r')
# 0: port | 1: server path |2: batch file path
data = []
for each in file:
data.append(each)
port = int(data[0][0:len(data[0]) - 1])
ip = data[1][0:len(data[1]) - 1]
name = data[2][0:len(data[2]) - 1]
return [port,ip,name]
def init_data_in_file():
port = int(input("Enter Sever Port\n>>> "))
ip = input('Enter Server ip\n>>> ')
name = input('Enter username (10 characters max)\n>>> ')
#error checkinag
if len(name) > 10:
name = name[0:10]
f = open("client.data","wt")
f.write(str(port)+'\n')
f.write(ip+'\n')
f.write(name+'\n')
f.close()
def run():
port,ip,name = load_data_from_file()
request = int(input("[1] Sever Up | [2] Server Down | [3] Server Status\n>>> "))
s = socket.socket()
s.connect((ip,port))
s.send(request.to_bytes(2,'big'))
result = s.recv(2048)
print(result)
input(">>> ")
s.close()
if int(input('[1] continue |[2] quit\n>>> ')) == 1:
start()
def start():
#checking to make sure data is setup
f = open('client.data','r')
data = f.read()
if data == '' or len(data) > 0 and data[0] == ' ':
init_data_in_file()
f.close()
prompt = "[1] connecting |[2] For Changing Client Settings\n>>> "
choice = int(input(prompt))
if choice == 2:
init_data_in_file()
start()
else:
run()
print("CURRENT VERSION: "+VERSION)
start()