-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartServer.py
More file actions
39 lines (30 loc) · 1.05 KB
/
startServer.py
File metadata and controls
39 lines (30 loc) · 1.05 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
#!/usr/bin/python
import socket, time, os, sys, copy
ip = "0.0.0.0"
port = 54321
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip, port))
s.listen(2)
print "Listening on {}:{}".format(ip,port)
go = 1
while go:
client, address = s.accept()
file = str(time.time())+".jpg"
print "Connection made from {}:{}".format(address[0],address[1])
data = client.recv(1024)
while go:
oldData = data
data = data + client.recv(1024)
if oldData == data:
break
#Get into long hex string
checkData = copy.copy(data)
checkData = str(data).encode('hex')
# print ("recieved data is: {}".format(data))
if ('ffd8' and 'ffd9') in checkData:
with open(file, "w+") as f:
f.write(data)
os.rename(file,str("testImages/"+str(file)))
print("Image written")
else:
print("Valid image not detected")