I'm trying to send data over UDP point to point (looping back to a second NIC) but it is not working. (This will be a one way connection which is why I am using UDP). I'm using Python 2.6.6. Here is the code (from: sending/receiving file UDP in python):
----- sender.py ------
#!/usr/bin/env python
from socket import *
import sys
s = socket(AF_INET,SOCK_DGRAM)
s.bind(("192.168.0.1",9999))
host = "192.168.100.1"
port = 9999
buf =1024
addr = (host,port)
file_name=sys.argv[1]
s.sendto(file_name,addr)
f=open(file_name,"rb")
data = f.read(buf)
while (data):
if(s.sendto(data,addr)):
#print "sending ..."
data = f.read(buf)
s.close()
f.close()
----- receiver.py -----
#!/usr/bin/env python
from socket import *
import sys
import select
host="192.168.100.1" #second nic
port = 9999
s = socket(AF_INET,SOCK_DGRAM)
s.bind((host,port))
addr = (host,port)
buf=1024
data,addr = s.recvfrom(buf)
print "Received File:",data.strip()
f = open(data.strip(),'wb')
data,addr = s.recvfrom(buf)
try:
while(data):
f.write(data)
s.settimeout(2)
data,addr = s.recvfrom(buf)
except timeout:
f.close()
s.close()
print "File Downloaded"
I can see both interfaces using ifconfig
. eth0
is 192.168.0.1
and eth1
is 192.168.100.1
. If I try ping -I eth0 192.168.100.1
, I see packets sent on eth0
and received on eth1
. This seems to confirm the interface works. However, if I run the above python script, I see no packets being sent or received on either interface.