![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 9
Rep Power: 0
![]() |
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");
}
}
} |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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 <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Jan 2005
Posts: 9
Rep Power: 0
![]() |
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:
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? |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|