-1

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
    address 192.168.1.105
    netmask 255.255.255.0
    gateway 192.168.1.106

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 = "192.168.1.105"
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.

1 Answers1

0

It is extremely unlikely that your gateway is 192.168.1.106

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.

Milliways
  • 59,890
  • 31
  • 101
  • 209