Can anyone help, please?

M

maehhheeyy

Hi, right now I'm using Python and Multicast. I have the code for
Multicast receiver on Python but I keep getting this error;

File "<string>", line 1, in bind
error: (10049, "Can't assign requested address")


The error is coming from this line;
sock.bind ((MCAST_ADDR, MCAST_PORT))

This is the code that I am using:

import socket
import time

ANY = "0.0.0.0"
SENDERPORT = 1501
MCAST_ADDR = "224.168.2.9"
MCAST_PORT = 1600

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)

sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
status = sock.setsockopt(socket.IPPROTO_IP,
socket.IP_ADD_MEMBERSHIP,
socket.inet_aton(MCAST_ADDR) +
socket.inet_aton(ANY));

sock.setblocking(0)
ts = time.time()
while 1:
try:
data, addr = sock.recvfrom(1024)
except socket.error, e:
pass
else:
print "We got data!"
print "FROM: ", addr
print "DATA: ", data

I'm using the UDP multicast. Is there anything that I did wrong in
this code?

Can anyone please help me solve this problem?
 
P

Paul McGuire

Hi, right now I'm using Python and Multicast. I have the code for
Multicast receiver on Python but I keep getting this error;

File "<string>", line 1, in bind
error: (10049, "Can't assign requested address")

The error is coming from this line;
sock.bind ((MCAST_ADDR, MCAST_PORT))

This is the code that I am using:
I'm using the UDP multicast. Is there anything that I did wrong in
this code?

Can anyone please help me solve this problem?

I cannot help you directly, but googling for this error number and
message and chasing a few Usenet posts led me to "Beej's Guide to
Network Programming Using Internet Sockets" (http://beej.us/guide/
bgnet/), which someone else having your problem reported to have been
helpful (and it looks like it was recently updated).

Good luck,
-- Paul
 
D

Douglas Wells

Hi, right now I'm using Python and Multicast. I have the code for
Multicast receiver on Python but I keep getting this error;

Hi,

In the future please use a Subject: line that is relevant to your
inquiry. Many people only read articles with "interesting"
subjects. This is particularly true in groups like this one with
200+ messages a day.
File "<string>", line 1, in bind
error: (10049, "Can't assign requested address")

The error is coming from this line;
sock.bind ((MCAST_ADDR, MCAST_PORT))

You didn't provide either the OS that you're running on, nor your
network interface configuration, both of which are relevant to use
of IP-multicast. (Many/most languages, including Python, do not
have a separate networking model: they simply provide access to
the one provided by the target platform.
This is the code that I am using:

[ ... ]

ANY = "0.0.0.0"
[ ... ]

status = sock.setsockopt(socket.IPPROTO_IP,
socket.IP_ADD_MEMBERSHIP,
socket.inet_aton(MCAST_ADDR) +
socket.inet_aton(ANY));

If I had to guess based on facts available, I would guess that
your operating system requires you to select the appropriate
interface. Try replacing the second argument (the "ANY" one) with
the address of the networking interface over which you wish to
communicate. Note that the interface *must* be multicast-capable
(on many platforms), and "localhost" usually is not. So, you want
an/the address on your Ethernet interface, for example.

I include below an example program that works on my system (FreeBSD)
and has been somewhat altered to be similar to your failing test case.

- dmw

=========================================================================
#! /usr/bin/env python

# Receiver:

##############################

import socket
import struct
import time

MULTICAST_ADDR = '225.0.0.1'
PORT = 1200
REPORT_LENGTH = 1024000
BUFFSIZE = 1024

ANY_IPADDR = struct.pack ("!L", socket.INADDR_ANY)
INTERFACE_ADDR = socket.gethostbyname (socket.gethostname ())

ip = socket.inet_aton (MULTICAST_ADDR) + socket.inet_aton (INTERFACE_ADDR)

sock = socket.socket (socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

sock.setsockopt (socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, ip)

sock.bind ((socket.inet_ntoa (ANY_IPADDR), PORT))

start = time.time ()
total_data_length = 0
print 'Listening ...'

while 1:
try:
data, addr = sock.recvfrom (BUFFSIZE)
total_data_length += len (data)
if (total_data_length % REPORT_LENGTH) == 0:
elapsed = time.time () - start
print "%7.3f: %d octets from %s" % (elapsed, total_data_length, addr)
except socket.error, e:
print "Socket error" + e
break

##############################

=========================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top