471,325 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Multicast Invalid Argument

I'm trying to set a multicast server but I get "Invalid argument" when
setting multicast options.
Below is the code that gives me problems more precisely in
SetSocketOption with the AddMembership name... it exits with a runtime
error telling me "An invalid argument was supplied". Does anyone know
how to fix this?
-------------------------------
public MulticastServer(string IPAddressString)
{
//Create multicast socket
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp);
IPAddress ip=IPAddress.Parse(IPAddressString);
socket.SetSocketOption(SocketOptionLevel.IP,Socket OptionName.AddMembership,new
MulticastOption(ip));
socket.SetSocketOption(SocketOptionLevel.IP,Socket OptionName.MulticastTimeToLive,2);
IPEndPoint ep=new IPEndPoint(ip,5000);
//socket.Connect(ep);
}

Jan 12 '06 #1
5 5340
Nuno Magalhaes wrote:
I'm trying to set a multicast server but I get "Invalid argument" when
setting multicast options.
Below is the code that gives me problems more precisely in
SetSocketOption with the AddMembership name... it exits with a runtime
error telling me "An invalid argument was supplied". Does anyone know
how to fix this?
-------------------------------
public MulticastServer(string IPAddressString)
{
//Create multicast socket
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp);
IPAddress ip=IPAddress.Parse(IPAddressString);
socket.SetSocketOption(SocketOptionLevel.IP,Socket OptionName.AddMembership,new
MulticastOption(ip));
socket.SetSocketOption(SocketOptionLevel.IP,Socket OptionName.MulticastTimeToLive,2);
IPEndPoint ep=new IPEndPoint(ip,5000);
//socket.Connect(ep);
}


The docs say:
<quote>
Windows 98, Windows NT 4.0 Platform Note: You must call the Bind
method before using AddMembership as the optionName parameter.
</quote>

Have you tried that?

Jon

Jan 12 '06 #2
I didn't try but now it's another on bind: "The requested address isn't
valid". The IPAddressString is 224.1.2.3 and the code is below:
---------------------------------
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp);
IPAddress ip=IPAddress.Parse(IPAddressString);
IPEndPoint ep=new IPEndPoint(ip,5000);
socket.Bind(ep);

Jan 12 '06 #3
Nuno Magalhaes wrote:
I didn't try but now it's another on bind: "The requested address isn't
valid". The IPAddressString is 224.1.2.3 and the code is below:
---------------------------------
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp);
IPAddress ip=IPAddress.Parse(IPAddressString);
IPEndPoint ep=new IPEndPoint(ip,5000);
socket.Bind(ep);


And is the machine you're running on 224.1.2.3?

Jon

Jan 12 '06 #4
No but I fixed it now.
In Ethereal the socket send command will generate entries like this:
Time: 0.0s
Source: 10.154.0.104 SourcePort:5000
Destination: 224.1.2.3 DestPort:5000
Is this normal since my code is written like shown below. Is this a
good programming style?
Thanks for the comments.
-------------------------------
public MulticastServer(string IPAddressString)
{
//Create multicast socket
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp);
IPHostEntry IPHost=Dns.GetHostByName(Dns.GetHostName());
IPAddress ip=IPAddress.Parse(IPHost.AddressList[0].ToString());
IPEndPoint ep=new IPEndPoint(ip,5000);
socket.Bind(ep);

IPAddress ip2=IPAddress.Parse(IPAddressString);
IPEndPoint ep2=new IPEndPoint(ip2,5000);
socket.SetSocketOption(SocketOptionLevel.IP,Socket OptionName.AddMembership,new
MulticastOption(ip2));
socket.SetSocketOption(SocketOptionLevel.IP,Socket OptionName.MulticastTimeToLive,2);
socket.Connect(ep2);
}

Jan 12 '06 #5
Nuno Magalhaes <nu************@hotmail.com> wrote:
No but I fixed it now.
In Ethereal the socket send command will generate entries like this:
Time: 0.0s
Source: 10.154.0.104 SourcePort:5000
Destination: 224.1.2.3 DestPort:5000
Is this normal since my code is written like shown below. Is this a
good programming style?


I'm not sure why it wouldn't be normal - what exactly are you asking
about? The code is fairly reasonable, although I suspect there are
better ways of getting the local endpoint. (I don't do this often
enough to know the best way offhand, I'm afraid.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Pradeep MM | last post: by
5 posts views Thread by Mariame | last post: by
1 post views Thread by llevi | last post: by
4 posts views Thread by robert | last post: by
1 post views Thread by max.aginaga | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.