-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.py
45 lines (29 loc) · 960 Bytes
/
Server.py
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
import socket, platform, os
SRV_ADDR = input("Enter the Server Address: ")
SRV_PORT = 6666
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((SRV_ADDR, SRV_PORT))
s.listen(1)
connection, address = s.accept()
while 1:
try:
data = connection.recv(1024)
except:
continue
if(data.decode('utf-8') == '1'):
tosend = platform.platform() + " " + platform.machine()
connection.sendall(tosend.encode())
elif(data.decode('utf-8') == '2'):
data = connection.recv(1024)
try:
filelist = os.listdir(data.decode('utf-8'))
tosend = ""
for x in filelist:
tosend += "," + x
except:
tosend = "Wrong Path!"
connection.sendall(tosend.encode())
elif (data.decode ('utf-8') == '3'):
connection.close()
connection, address = s.accept ( )