Handle message parsing in connection
This commit is contained in:
parent
1365226c00
commit
8501aab7c3
@ -6,6 +6,8 @@ import socket
|
|||||||
import ssl
|
import ssl
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from . import messages
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
"""
|
"""
|
||||||
Establishes a connection to the OM Application XML Interface
|
Establishes a connection to the OM Application XML Interface
|
||||||
@ -46,6 +48,8 @@ class Connection:
|
|||||||
:param message: Message string
|
:param message: Message string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
message = messages.construct(message)
|
||||||
|
|
||||||
self._socket.send(message.encode("utf-8") + b"\0")
|
self._socket.send(message.encode("utf-8") + b"\0")
|
||||||
|
|
||||||
def _receive_loop(self):
|
def _receive_loop(self):
|
||||||
@ -74,6 +78,8 @@ class Connection:
|
|||||||
message, buffer = recv_buffer.split(b"\0", 1)
|
message, buffer = recv_buffer.split(b"\0", 1)
|
||||||
recv_buffer = buffer
|
recv_buffer = buffer
|
||||||
|
|
||||||
|
message = message.decode("utf-8")
|
||||||
|
message = messages.parse(message)
|
||||||
self._received_messages.put(message)
|
self._received_messages.put(message)
|
||||||
|
|
||||||
def recv(self):
|
def recv(self):
|
||||||
@ -86,7 +92,7 @@ class Connection:
|
|||||||
if self._received_messages.empty():
|
if self._received_messages.empty():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self._received_messages.get().decode("utf-8")
|
return self._received_messages.get()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
|
@ -76,8 +76,6 @@ class Session:
|
|||||||
'PingResp'
|
'PingResp'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
message = messages.construct(request)
|
self._connection.send(request)
|
||||||
self._connection.send(message)
|
|
||||||
|
|
||||||
res = self._wait_for_respose()
|
return self._wait_for_respose()
|
||||||
return messages.parse(res)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user