[Python] Oracle instance: UDP flow interrupted under certain conditions

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to send and receive udp packets to a lte modem ( UDP is obligatory, no TCP) and its doing it just fine in some configuratiosn but not in others. When i send it every 1min it works fine for 1h as well as when its set to send every 30min, but when i send it ever 10min for 1h, it stops sending after the 20min packet. here is the code im running. time variable can be changed at bottom.there is no logs as there is no errors being outputed,as if the code just stopped running on purpose or something. One thing that is happening to is that when its set to 10min, the ssh terminal will just freeze and nothing will show up anymore tho the code still seems to be running in the background until it fails at 30min and then shows error Network error: Software caused connection abort.Note: im using oracle free tier instance running ubuntu and i have contacted them but they are pretty useless i have to say

    python3 -c '
    import socket
    import time
    import requests
    from datetime import datetime


    try:
    PUBLIC_IP = requests.get("https://api64.ipify.org").text
    except Exception as e:
    PUBLIC_IP = "Unknown"
    print(f"Could not retrieve public IP: {e}")


    UDP_IP = "--.--.--.--"# actual ip is set during the testing and im 100% that isnt the problem
    UDP_PORTS = [36000] # List of ports
    MESSAGE = b"Hello, this is a UDP test packet!" # Message to send

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    for i in range(6):
    for port in UDP_PORTS:
    try:
    # Send the UDP packet to each port
    sock.sendto(MESSAGE, (UDP_IP, port))
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(f"[{timestamp}] Packet {i+1} sent from {PUBLIC_IP} to {UDP_IP}:{port}")
    except Exception as e:
    print(f"[{timestamp}] Error sending packet to {port}: {e}")

    # Wait 10 minutes before sending the next batch
    if i < 5: # Avoid sleeping after the last send
    time.sleep(1800) # 600 seconds = 10 minutes


    sock.close()


    '


    I tried incorporating a keep alive packet as follows

    def tprint():
    while True:
    logging.info("Keep Alive")
    time.sleep(60)


    that didnt work. I tried different ports, different code. Nothing.

    Continue reading...

Compartilhe esta Página