summaryrefslogtreecommitdiffstats
path: root/src/ogClient.py
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2019-12-16 10:39:08 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commit77906be87fc67a49cf4a34fd0a03dfb7a10d74ae (patch)
treea378c29ab02681f5e4c88650a488d51100963ac1 /src/ogClient.py
parent2997952bc97871c140f3724a63a6c7fed6310f57 (diff)
Include disconnect and send function on client side
To disconnect the socket or send a message we use in different parts of the code the attribute socket which is declared inside of the client. This way will create us important problem in the future if we want to change the behavior in our client sockets. This patch adds two new methods inside the client and we can use them in other classes giving us the easy way to send messages and disconnect the client.
Diffstat (limited to 'src/ogClient.py')
-rw-r--r--src/ogClient.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/ogClient.py b/src/ogClient.py
index c1a911d..48ae5e7 100644
--- a/src/ogClient.py
+++ b/src/ogClient.py
@@ -44,6 +44,10 @@ class ogClient:
print ('Error connect ' + str(err))
+ def send(self, msg):
+ self.sock.send(bytes(msg, 'utf-8'))
+ return len(msg)
+
def connect2(self):
try:
self.sock.connect((self.ip, self.port))
@@ -85,14 +89,17 @@ class ogClient:
if self.trailer and len(self.data) >= self.content_len:
httpparser.parser(self.data)
- if not ogprocess.processOperation(httpparser.getRequestOP(), httpparser.getURI(), self.sock):
- self.state = State.FORCE_DISCONNECTED
+ ogprocess.processOperation(httpparser.getRequestOP(), httpparser.getURI(), self)
# Cleanup state information from request
self.data = ""
self.content_len = 0
self.trailer = False
+ def disconnect(self):
+ self.state = State.FORCE_DISCONNECTED
+ self.sock.close()
+
def run(self):
while 1:
sock = self.get_socket()