Gateway send RST for secon TCP message with socket Python

CAN to LAN gateway in DIN rail plastic casing
Post Reply
prunith
Posts: 1
Joined: Fri 6. Jun 2025, 14:15

Gateway send RST for secon TCP message with socket Python

Post by prunith » Tue 10. Jun 2025, 10:40

Hi,
i working to develop reliable and fast connection with gateway via sockets in TCP mode but i m not able to send more than one message.
Bellow script used and attache wireshark trace.

could you help me for debbuging?

Code: Select all

import socket
import time


# Adresse du serveur
SERVER_IP = '165.100.10.100'
SERVER_PORT = 50002

# Construction avec struct
# a CAN Frame ID= 0x000C1234,Type=ext ,Length=8,Data= 8F 8E B8 0C 00 00 00 00 
# See Developer Doku for Data Structure
#             0     1     2     3     4     5    6     7   8     9   10   11    12  13   14   15   16   17  18   19    20   21   22   23   24  25    26   27   28   29   30   31   32   33   34   35
msg_list = [0x00, 0x24, 0x00, 0x80, 0x9d, 0x7c, 0x3c,0xd5,0xf0,0x73,0xae,0x00,0x35,0xba,0x5e,0xf3,0x00,0x05,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x0D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

# Transform 
nachricht = bytes(msg_list)
# Envoi de la trame via TCP

try:
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        print(f"Connexion à {SERVER_IP}:{SERVER_PORT}...")
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE , 1)
        sock.connect((SERVER_IP, SERVER_PORT))

        print("Connexion établie. Envoi de la trame...")
        for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
            number_sent = sock.send(nachricht)
            if number_sent == 0:
                print("socket connection broken")
            sock.settimeout(1.0)  # 1 seconde max d’attente
            try:
                ack = sock.recv(1)
            except socket.timeout:
                pass  # pas de réponse, mais on continue
                print("No ack received.")
            time.sleep(0.05)

        time.sleep(10)
    print("Trame envoyée avec succès.")
except Exception as e:
    print(f"Erreur lors de l'envoi : {e}")
Attachments
gateway_RST_after_1st_Mesage.pcapng.txt
(8.4 KiB) Downloaded 84 times

S.Michaelsen
Hardware Development
Hardware Development
Posts: 87
Joined: Fri 10. Sep 2010, 13:11

Re: Gateway send RST for secon TCP message with socket Python

Post by S.Michaelsen » Tue 10. Jun 2025, 11:22

Hi,

did you follow the developer gude and e.g. disable the handshake mechanism on the routes you're trying to use?


BR,
Stephan

Post Reply