-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_sever.py
More file actions
63 lines (48 loc) · 1.65 KB
/
main_sever.py
File metadata and controls
63 lines (48 loc) · 1.65 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
import socket # Import socket module
from threading import Thread
import subprocess
from _thread import *
import threading
#import attendence as att
import requests
import trial as tt
data2 = ""
def on_new_client(conn, addr):
#start_new_thread(att.attendence, ())
fac_id = conn.recv(1024)
fac_id = fac_id.decode("utf-8").strip()
print(fac_id)
abc=fac_id.split(",")
userdata = {"facid": abc[0], "time": abc[3], "subject": abc[1],"semester":abc[2]}
resp = requests.post('http://127.0.0.1/attendence/mark_attendence.php', params=userdata)
tt.attendence(abc[0],abc[3],abc[1],abc[2])
#t1 = Thread(target=tt.attendence, args=(abc[0]))
#t1.start()
#t1.join()
#att.attendence()
#att.conn.close()
print('Got connection from', addr)
print("con.close")
conn.close()
port = 40000
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(150)
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))
#t1 = Thread(target=tt.attendence, args=())
#t1.start()
#t1.join()
print('Got connection from', addr)
# data = conn.recv(1024)
# print('Server received', data)
# conn.send(bytes(repr('Thank you for connecting'), 'utf-8'))
print("closed")
conn.close()