Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2005, 8:18 AM   #1
theitalianjobdesign
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 theitalianjobdesign is on a distinguished road
socket and multicasting...

Hi!

I'm studying sockets and I'm having a bit of headache with multicasting.

It's nearly a week that I'm searching the net but I couldn't find much help.
It seems there's no much topics about multicasting and even less about problem with multicasting.

I have a basic Send class that should multicast a string message to a group. Well it throws a System.Net.Sockets.SocketException with Errorcode 10022, Invalid Argument at

s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
new MulticastOption(ip));

The code are actually from the tutorial at http://www.codeproject.com/csharp/multicast.asp.

Please help

using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Runtime.Serialization;
using System.Text;


namespace multiCastSend
{
class send
{
send(string mcastGroup, string port, string ttl, string rep) 
{
IPAddress ip;
try 
{
Console.WriteLine("MCAST Send on Group: {0} Port: {1} TTL: {2}",mcastGroup,port,ttl);
ip=IPAddress.Parse(mcastGroup);

Socket s=new Socket(AddressFamily.InterNetwork, 
   SocketType.Dgram, ProtocolType.Udp);
								
// ||||||||| the following SetSocketOption throws the exception |||||||||

s.SetSocketOption(SocketOptionLevel.IP,
    SocketOptionName.AddMembership, new MulticastOption(ip));
				

s.SetSocketOption(SocketOptionLevel.IP, 
	SocketOptionName.MulticastTimeToLive, int.Parse(ttl));

byte[] b=new byte[10];

for(int x=0;x<b.Length;x++) b[x]=(byte)(x+65);
		
IPEndPoint ipep=new IPEndPoint(IPAddress.Parse(mcastGroup),int.Parse(port));

Console.WriteLine("Connecting...");

s.Connect(ipep);

 for(int x=0;x<int.Parse(rep);x++) {

Console.WriteLine("Sending ABCDEFGHIJ...");
s.Send(b,b.Length,SocketFlags.None);

					
}

Console.WriteLine("Closing Connection...");
s.Close();
} 
catch(System.Net.Sockets.SocketException e) { 


Console.Error.WriteLine(e.Message);
Console.Error.WriteLine(e.GetBaseException());
Console.Error.WriteLine(e.ErrorCode);
}
}

static void Main(string[] args)
{
new send("224.5.6.7", "5000", "50", "2");
}
}
}
__________________
Giuseppe
-----------------

www.theitalianjobdesign.com
theitalianjobdesign is offline   Reply With Quote
Old Feb 24th, 2005, 3:03 PM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Does you network actually support multicasting? I am assuming you actually know what it is at this point.

The issue with multicasting is that the Internet does not actually support it right now, and 99% of ISPs have multicasting disabled on their networks, even if you set up a LAN I think multicasting is disabled by default since for most practicalities LANs will not make efficient use of the protocol. This is most likely why you are not getting multicasting to work.

Set up a LAN which supports multicasting, make sure it is enabled (not sure how to check that at this moment) and make sure you bind specifically to the interfaces that support the multicasting and you will probably not get that error any longer.

In any case, good luck.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Feb 25th, 2005, 5:15 AM   #3
theitalianjobdesign
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 theitalianjobdesign is on a distinguished road
Lightbulb

Ok, I found the way to make it work.

I didn't notice the day I read the article (http://www.codeproject.com/csharp/multicast.asp ) that at the bottom of the page there was a little forum.
The problem were two:
First seems that XP sp2 and Windows 2003 throw an exception when the socket sender join a multicast group ( which is not needed in order to send, only the receivers need to join a multicast group in order to receive).
So, I commented out the line:

s.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, new MulticastOption(ip));

which was throwing the exception.

Once removed there was still one problem: the receiver seemed not to receive any data.
Well I later discovered that this occurs when there are multiple Network Cards or, in my case when there's more than one IP address binded. In my case my ISP, AO(hel)L gives me another 2 IPs on top of the one of my Nic which connets my Lan.

So as you were saying I had to make sure I was binding the socket to the desired interface.
This is accomplisced with the following codes:
IPAddress ipa = IPAddress.Parse("192.0.0.11");
int ad = (int) ipa.Address;
s.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.MulticastInterface, ad );

This seems to solve my problems.

Quote:
Originally Posted by kurifu
Does you network actually support multicasting? I am assuming you actually know what it is at this point.

The issue with multicasting is that the Internet does not actually support it right now, and 99% of ISPs have multicasting disabled on their networks, even if you set up a LAN I think multicasting is disabled by default since for most practicalities LANs will not make efficient use of the protocol. This is most likely why you are not getting multicasting to work.

Set up a LAN which supports multicasting, make sure it is enabled (not sure how to check that at this moment) and make sure you bind specifically to the interfaces that support the multicasting and you will probably not get that error any longer.

In any case, good luck.
Well as you said, multicasting is also implemented at the hardware level: the routers need to support Multicast and not many routers on internet support it (Even though I read, it's a matter of upgrading the router software and settings)
The following article anyway explains that a process called tunnelling manages to enable the delivery of multicast message over not multicast enabled networks.
http://www.microsoft.com/windows/win...e/multiwp.aspx

I couldn't try yet this class over the internet, just over my Lan (which doesn't have any router so of course it's fine) so I won't be able to say whether it works or not over the internet, but I'm confident it will because of tunnelling.

I'm pretty sure AOL is not multicast enabled ( actually when I rang them up and ask them, they (the technical department) didn't know what multicast is, they suggested me to go to their online help chat, as they said,it is more technical (?), but even the chat guys didn't know what multicast is. ( Are they a real ISP??? I couldn't believe!!! They didn't even know what contention ratio is and I had to explain to them!!!! How can they be so popular!?! )), anyway I was able to view some multicast streaming on my Real Player.

So it's seems that joining a multicast group from a not multicast enabled network is possible.

Anybody knows whether is possible to do all the way around: sending multicat messages from a non multicast network?
__________________
Giuseppe
-----------------

www.theitalianjobdesign.com
theitalianjobdesign is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC