I'm attempting to give my Raspberry Pi a static IP address on an ethernet network that I am controlling from a Windows machine.

I want to be able to send my PI UDP packets directly from my server via a static IP address. Here is how I have attempted to the assign a static IP to the PI and to bind it to an address in the /etc/network/interfaces

auto lo

iface lo inet loopback
iface eth0 inet static

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

And in my Python code:

import socket

UDP_IP = ""
UDP_PORT = 8888

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

while True:
   data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
   print "received message:", data

I am unable to bind to the IP address.

My question is, how can I set up my PI so that I can send messages to it via UDP?

Please let me know if you need anymore information or if I am misunderstanding anything.

| improve this question | | | | |

It is extremely unlikely that your gateway is

The /etc/network/interfaces you have would work (if you entered the correct values), but only by accident because dhcpcd disables itself. You would be better to follow the recommended settings, as described in How do I set up networking/WiFi/Static IP.

The above also explains how to find the correct values.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.