-
Notifications
You must be signed in to change notification settings - Fork 1
/
jioServer.py
executable file
·41 lines (31 loc) · 978 Bytes
/
jioServer.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
import json
class jioServer:
'Server Class for communication and calling function'
def __init__(self,port):
self.port = port
self.host = socket.gethostbyname(socket.gethostname())
self.s = socket.socket()
self.s.bind((self.host, self.port))
def listen(self):
self.s.listen(5)
print('JIOSERVER :: Host...',self.host)
print("JIOSERVER :: Listening on port...",self.port)
self.c, self.addr = self.s.accept()
print ("JIOSERVER :: Connected with Client on ",self.addr)
def recv_msg_call_func(self,func_file):
while True:
print("JIOSERVER :: Receiving message...")
msg = self.c.recv(1024)
print("LOG :: Message received : ",msg)
if msg=='exit' or msg=='':
break;
json_msg = json.loads(msg)
func_name = json_msg['func_name']
args = json_msg['args']
try:
ret_msg = getattr(func_file,func_name)(*args)
except Exception as e:
ret_msg = 'Error :: '+str(e)
self.c.send(ret_msg)
self.c.close()