-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
58 lines (48 loc) · 1.51 KB
/
server.py
File metadata and controls
58 lines (48 loc) · 1.51 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
import socket # Import socket module
import select
import sys
import getimage as im
import train_model as tr
from _thread import *
import threading
data2=""
def on_new_client(conn,addr):
data=conn.recv(1024)
data=data.decode("utf-8").strip()
file=data
global data2
data2="students/"+data+".mp4"
print(data)
print(data2)
with open(data2,'wb')as f:
print('file opened')
while True:
data=conn.recv(1024)
print('data=%s',(data))
if not data:
break
else:
f.write(data)
print('Done sending')
im.makeimage(file)
tr.train(file)
print ('Got connection from', addr)
f.close()
port = 60000
host = socket.gethostname() # Reserve a port for your service.
s = socket.socket() # Create a socket object
# Get local machine name
s.bind((host, port)) # Bind to the port
s.listen(5)
while True:
# Now wait for client connection.
print ("socket binded to %s" %(port))
print ('Server listening....')
print(socket.gethostbyname(socket.gethostname()))
conn, addr = s.accept() # Establish connection with client.
start_new_thread(on_new_client,(conn,addr))
print ('Got connection from', addr)
#data = conn.recv(1024)
#print('Server received', data)
#conn.send(bytes(repr('Thank you for connecting'), 'utf-8'))
conn.close()