UDP server only receives data from clients binded to specifc ports

I'm trying to establish an UDP communication between two Raspberry Pi via ethernet, but it seems my server only receives the client packets when the client is connectet to a specifc port.

Let's call them Rasp A and Rasp B. They have different software installed and different configurations.

Rasp A works both as a server and a client normally, but Rasp B shows some issues.

When I set B as a server and A as a client, B only receives A's packets when the client is binded to port 8002 or 8003. I'll put the scripts below.

Server code:

    import socket
    
    # localIP     = "169.254.155.4"
    localIP     = "128.30.1.198"
    
    localPort   = 8002
    bufferSize  = 1024
    
    msgFromServer = "Hello UDP Client"
    bytesToSend  = str.encode(msgFromServer)
    
    
    # Create a datagram socket
    UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
    
    # Bind to address and ip
    UDPServerSocket.bind((localIP, localPort))
    
    print("UDP server up and listening")
    
    # Listen for incoming datagrams
    try:
      while(True):
        bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
        message = bytesAddressPair[0]
        address = bytesAddressPair[1]
    
        clientMsg = "Message from Client:{}".format(message)
        clientIP  = "Client IP Address:{}".format(address)
    
        print(clientMsg)
        print(clientIP)
    
        # Sending a reply to client
        UDPServerSocket.sendto(bytesToSend, address)
        # UDPServerSocket.close()
    
    except Exception as ex:
            print (ex)
            UDPServerSocket.close()

Client code:

import socket

 

msgFromClient       = "Hello UDP Server"

bytesToSend         = str.encode(msgFromClient)

serverAddressPort   = ("128.30.1.198", 8002)

bufferSize          = 1024

 

# Create a UDP socket at client side
print('creating socket')
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
UDPClientSocket.bind(('128.30.1.2',8002))


# Send to server using created UDP socket
print('sending message')
UDPClientSocket.sendto(bytesToSend, serverAddressPort)

 
print('receiving message')
msgFromServer = UDPClientSocket.recvfrom(bufferSize)

 

msg = "Message from Server {}".format(msgFromServer[0])

print(msg)

Rasp B will only receive packets as expected when the client is binded to port 8002 or 8003, not receiveing anything if the socket is binded to any other port or not binded at all. Here are some sniffed packets:

Working Comm

Client sends >>>

###[ IP ]### 
     version   = 4
     ihl       = 5
     tos       = 0x0
     len       = 44
     id        = 5063
     flags     = DF
     frag      = 0
     ttl       = 64
     proto     = udp
     chksum    = 0x23f6
     src       = 128.30.1.2
     dst       = 128.30.1.198
     \options   \
###[ UDP ]### 
        sport     = 8003
        dport     = 8002
        len       = 24
        chksum    = 0xc98f
###[ Raw ]### 
           load      = 'Hello UDP Server'
###[ Padding ]### 
              load      = '\x00\x00'

Server gets this message and responds <<<

###[ IP ]### 
     version   = 4
     ihl       = 5
     tos       = 0x0
     len       = 44
     id        = 35228
     flags     = DF
     frag      = 0
     ttl       = 64
     proto     = udp
     chksum    = 0xae20
     src       = 128.30.1.198
     dst       = 128.30.1.2
     \options   \
###[ UDP ]### 
        sport     = 8002
        dport     = 8003
        len       = 24
        chksum    = 0x32e
###[ Raw ]### 
           load      = 'Hello UDP Client'

Not working comm: Client sends >>>

###[ IP ]### 
     version   = 4
     ihl       = 5
     tos       = 0x0
     len       = 44
     id        = 6060
     flags     = DF
     frag      = 0
     ttl       = 64
     proto     = udp
     chksum    = 0x2011
     src       = 128.30.1.2
     dst       = 128.30.1.198
     \options   \
###[ UDP ]### 
        sport     = 8002
        dport     = 8004
        len       = 24
        chksum    = 0xc98e
###[ Raw ]### 
           load      = 'Hello UDP Server'
###[ Padding ]### 
              load      = '\x00\x00'

Server does not receive this message and doesn't respond.

Could it be something related to firewall configuration?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum