Commit 26ee0ed1 authored by Yori Fournier's avatar Yori Fournier
Browse files

Some minor changes

parent 9f42d865
......@@ -4,7 +4,7 @@ from .myData import MyData
D_VERSION='v5'
D_HIERARCHY='SERVER'
D_HOST='localhost'
D_PORT=50228
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
......
from . import socket, AF_INET, SOCK_STREAM
from . import D_HOST
from . import D_PORT
from . import INFO, DBUG, WARN, SEVR, SPCE
class Server():
......@@ -8,10 +9,11 @@ class Server():
def __init__(self):
self.soc = socket(AF_INET, SOCK_STREAM)
# self.soc.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # requires some extra import
self.host = D_HOST
self.port = D_PORT
self.answer = None
# self.answer = False
def init(self):
......@@ -20,25 +22,27 @@ class Server():
def run(self):
answer = False
while True:
if not self.answer:
if not answer:
conn, addr = self.soc.accept()
print(INFO + 'Connected by ' + str(addr))
self.answer = conn.recv(1024)
answer = conn.recv(1024)
if self.answer in ('KILL', 'kill', 'Kill'):
if answer in ('KILL', 'kill', 'Kill'):
print(INFO+"Recieved 'Kill' signal.")
conn.close()
break
else:
self.treatAnswer()
self.treatAnswer(answer)
def treatAnswer(self):
def treatAnswer(self, answer):
try:
exec(str(self.answer))
exec(str(answer))
except:
print(INFO+"I could not execute the command")
print(INFO+'Received: '+str(self.answer))
print(INFO+'Received: '+str(answer))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment