Skip to content

Commit 33623a6

Browse files
author
tiagoepr
committed
Solved bug with MLLP socket
1 parent 50273d8 commit 33623a6

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

mllp_http_https/https2mllp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def send(self, data):
8181
if connection is None:
8282
connection = self._connect()
8383
response = connection.send(data)
84-
if self.options.max_messages <= connection.message_count and self.options.max_messages >= 0:
84+
if connection.message_count >= self.options.max_messages >= 0:
8585
connection.close()
8686
else:
8787
connection.last_update = time.monotonic()
@@ -148,6 +148,10 @@ def __init__(self, request, address, server, mllp_client,
148148
self.mllp_parser = mllp_parser
149149
super().__init__(request, address, server)
150150

151+
# Disable log from handler
152+
def log_message(self, format, *args):
153+
pass
154+
151155
# For Authentication
152156
def do_AUTHHEAD(self):
153157
self.send_response(401)
@@ -264,6 +268,7 @@ def serve(address, options, mllp_address, mllp_options):
264268
try:
265269
server = http.server.ThreadingHTTPServer(address, handler)
266270

271+
267272
# >> Dealing with SSL/TLS on the HTTP server side
268273
# For Python > 3.7
269274
context = ssl.SSLContext(ssl.PROTOCOL_TLS)

mllp_http_https/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,4 @@ def mllp2https():
537537

538538
# For debugging reasons
539539
#mllp2https()
540-
#https2mllp()
540+
https2mllp()

mllp_http_https/mllp.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ def send_mllp(socket, content):
108108
socket.sendall(bytes([Format.END_BLOCK, Format.CARRIAGE_RETURN]))
109109

110110
# Wait for the ACK/NACK
111-
response = socket.recv(4096)
112-
return response
111+
response = bytearray()
112+
end_block = bytes([Format.END_BLOCK])
113+
while True:
114+
if end_block in response:
115+
# print('finished', bytes(response))
116+
break
117+
else:
118+
packet = socket.recv(1024)
119+
if not packet:
120+
break
121+
else:
122+
response.extend(packet)
123+
# print(bytes(response))
124+
return bytes(response)
113125

mllp_http_https/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.39"
1+
__version__ = "1.2.40"

0 commit comments

Comments
 (0)