M0r13n / pyais

AIS message decoding and encoding in Python (AIVDM/AIVDO)
MIT License
176 stars 61 forks source link

TCPConnection stops receiving messages #133

Closed mnaranjo closed 4 months ago

mnaranjo commented 5 months ago

Hello,

I am trying to maintain a TCP stream connection with an AIS data stream, however after a period of several minutes (it is an indeterminate time, sometimes almost 1h, sometimes not even 15min), the following code appears:

for msg in TCPConnection(AIS_STREAM_IP, port=AIS_STREAM_PORT): print(msg)

stops printing received messages. Could this be due to the implementation of Socket in the TCPConnection object?

I don't get any exception about it, it seems that no more messages arrive and therefore the code waits for more. If I try a connection to the same IP and port with the Telnet command I still receive messages, so the stream has content.

Best regards.

M0r13n commented 4 months ago

@mnaranjo

This sounds odd. I tried to reproduce this phenomenon by establishing a TCP connection with an AIS sender. In my case, the connection never stalls - at least not for 20 minutes (I terminated the program afterwards).

You could try to create a plain old socket and connect to your peer manually to check if the error still occurs:

import socket

host = '153.44.253.27'
port = 5631

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.connect((host, port))

    while True:
        body = sock.recv(4096)
        for line in body.splitlines():
            print(line)
mnaranjo commented 4 months ago

Thank you for your reply. We are in the process of testing to be able to rule out that it is a problem with the source. The loss of connection is not periodic, and each time it cuts off at a different time interval. In any case, we will consider this option. Thank you very much.

M0r13n commented 4 months ago

@mnaranjo Any updates? May I close this issue?

Best wishes, Leon

mnaranjo commented 4 months ago

Sorry for not responding sooner. Yes, it can be closed, in the end we found that there was an error with the source of the stream. Thank you very much