I don't know if it the case of network config or something is wrong with my software.
I have a device whose address is 192.168.4.83
. This device is connected directly to my pc linux server, which has address 192.168.4.11
.
I want to send a UDP packet from a server to the device, using python. The server is also listening for responses. I have a simple python script to do that. I send using:
self.sendSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sendSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
sock.sendSocket.send(msg,('<boradcast>', UDP_PORT))
I listen and bind to 0.0.0.0. The code is very simple: one thread is sending udp packets, the other one has while(1) loop which only receives packets.
This is the listening code:
class CUdp(threading.Thread):
def __init__(self, log=False):
threading.Thread.__init__(self)
self.running = True
self.listenSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.listenSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.listenSocket.bind(("", UDP_PORT))
self.last_time = 0
self.now = 0
self.log = log
def run(self):
global sent_time
while(self.running):
data, addr = self.listenSocket.recvfrom(1024)
if data != None:
recv_time = time.time()
myprint("[RECV " + str(datetime.datetime.now()) + "] (len=" + str(len(data)) +") : " + str(data)+"\n", self.log)
The strange thing is that, on wireshark i can see that: packet has been sent from 192.168.4.11
to 255.255.255.255
, and device has responded to this packet - packet from 192.168.4.83
has been sent to 255.255.255.255
. It seems, that using bind (0.0.0.0, port) does not cover 255.255.255.255
. I'm lost and I have no ideas.
ifconfig is:
eth0 Link encap:Ethernet HWaddr 2C:41:38:9B:BF:CA
inet addr:192.168.4.11 Bcast:192.168.4.255 Mask:255.255.255.0
inet6 addr: fe80::2e41:38ff:fe9b:bfca/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:34 errors:0 dropped:0 overruns:0 frame:0
TX packets:413 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5050 (4.9 KiB) TX bytes:26688 (26.0 KiB)
Interrupt:17
Any clues?