Home > OS >  Python UDP socket - can not recieve any data
Python UDP socket - can not recieve any data

Time:10-29

I want to recieve data by using UDP socket in Python. I send UDP data from my external HW every 1 second (connected with my PC via Ethernet cable). Also I can see data in the Wireshark:

enter image description here

and also I can recieve data in Hercules:

enter image description here

Also I can ping to my HW and get response.

What I have already tried

import socket

localIP     = "192.168.0.10" 
localPort   = 9999
bufferSize  = 1024

# Create a datagram socket
sckt = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
# Bind to address and ip
sckt.bind(('', localPort))

print("UDP server up and listening")
# Listen for incoming datagrams

while True:
    
    bytesAddressPair = sckt.recvfrom(bufferSize)

    message = bytesAddressPair[0]
    address = bytesAddressPair[1]

    clientMsg = "Message from Client:{}".format(message)
    clientIP  = "Client IP Address:{}".format(address)
    
    print(clientMsg)
    print(clientIP)

This can not recieve any data - it stuck on sckt.recvfrom(bufferSize)

Any help please? Thank you.

CodePudding user response:

Disabling firewall is the solution - now it works!

  • Related