473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how to set SocketOptionName.MulticastInterface

Hi All,

Following code is used to set multicast interface :

IPAddress ipLan = IPAddress.Parse("...");
int iIP = (int)(ipLan.Address) ;

objMCastSender.SetSocketOption(SocketOptionLevel.I P,SocketOptionName.Multica
stInterface , iIP) ;

When the IP address is "192.168.0.231" , Overflow error occur. but if change
the code to:

IPAddress ipLan = IPAddress.Parse("...");
long iIP = (long)(ipLan.Address) ;

objMCastSender.SetSocketOption(SocketOptionLevel.I P,SocketOptionName.Multica
stInterface , iIP) ;

Another error occur: optionerror.

Would you please give me some advise about how to solve it .

Thanks,

Phlics
Nov 15 '05 #1
3 8668
"PHLICS_Admin" <ph****@hotmail.com> wrote in message news:<uQ*************@tk2msftngp13.phx.gbl>...
Hi All,

Following code is used to set multicast interface :

IPAddress ipLan = IPAddress.Parse("...");
int iIP = (int)(ipLan.Address) ;

objMCastSender.SetSocketOption(SocketOptionLevel.I P,SocketOptionName.Multica
stInterface , iIP) ;

Would you please give me some advise about how to solve it .

Phlics -

You don't need to convert the IP address to an int for it to work.
You can use the GetAddressBytes() IPAddress method, and then use that
value for the SetSocketOption() method. This worked fine on my PC:

Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
IPAddress ipLan = IPAddress.Parse("192.168.1.10");
byte[] bIP = ipLan.GetAddressBytes();
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastInterface,
bIP);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("224.100.0.1"),
9050);
byte[] data = Encoding.ASCII.GetBytes("This is a test");
sock.SendTo(data, iep);
sock.Close();

Hope this helps shed some light on your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Nov 15 '05 #2
Thanks for your help .

Microsoft KB number 318911 say:

When you use MulticastInterface as the value for the SocketOptionName
enumeration, the optionValue expects an Index value of the particular
Network Adapter or Interface. Note that there is currently no API in the
..NET Framework to determine the index of a particular adapter. Therefore,
the user must input the index value

I wonder whether your method can work correctly.

Regards.

Phlics

"Rich Blum" <ri*******@juno.com> ????
news:cc**************************@posting.google.c om...
"PHLICS_Admin" <ph****@hotmail.com> wrote in message

news:<uQ*************@tk2msftngp13.phx.gbl>...
Hi All,

Following code is used to set multicast interface :

IPAddress ipLan = IPAddress.Parse("...");
int iIP = (int)(ipLan.Address) ;

objMCastSender.SetSocketOption(SocketOptionLevel.I P,SocketOptionName.Multica stInterface , iIP) ;

Would you please give me some advise about how to solve it .

Phlics -

You don't need to convert the IP address to an int for it to work.
You can use the GetAddressBytes() IPAddress method, and then use that
value for the SetSocketOption() method. This worked fine on my PC:

Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
IPAddress ipLan = IPAddress.Parse("192.168.1.10");
byte[] bIP = ipLan.GetAddressBytes();
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastInterface,
bIP);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("224.100.0.1"),
9050);
byte[] data = Encoding.ASCII.GetBytes("This is a test");
sock.SendTo(data, iep);
sock.Close();

Hope this helps shed some light on your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html

Nov 15 '05 #3
It can work.

Thanks,

"Rich Blum" <ri*******@juno.com> ????
news:cc**************************@posting.google.c om...
"PHLICS_Admin" <ph****@hotmail.com> wrote in message

news:<uQ*************@tk2msftngp13.phx.gbl>...
Hi All,

Following code is used to set multicast interface :

IPAddress ipLan = IPAddress.Parse("...");
int iIP = (int)(ipLan.Address) ;

objMCastSender.SetSocketOption(SocketOptionLevel.I P,SocketOptionName.Multica stInterface , iIP) ;

Would you please give me some advise about how to solve it .

Phlics -

You don't need to convert the IP address to an int for it to work.
You can use the GetAddressBytes() IPAddress method, and then use that
value for the SetSocketOption() method. This worked fine on my PC:

Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
IPAddress ipLan = IPAddress.Parse("192.168.1.10");
byte[] bIP = ipLan.GetAddressBytes();
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastInterface,
bIP);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("224.100.0.1"),
9050);
byte[] data = Encoding.ASCII.GetBytes("This is a test");
sock.SendTo(data, iep);
sock.Close();

Hope this helps shed some light on your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nathan Kerr | last post by:
I have been working with KB Article 812404 "HOW TO: Write Pluggable Protocol to Supprot FTP in Managed Classes by Using Visual Bassic.NET". I have modified the code to run on a Pocket PC. In the...
0
by: Ivar | last post by:
Hi, Is SocketOption.NoDelay working ? There is some trouble with socket delay, I doubt that SocketOption.NoDelay isn't working. If I set...
0
by: Ivar | last post by:
Hi, Is SocketOptionName.ReciveTimeout usable with asyncronous socket methods ? With Recive method it works but BeginRecive can't get it working.
0
by: Edward Diener | last post by:
After calling mySocket.Bind(someEndpoint) to an IP endpoint I immediately attempt to get the MaxConnections allowed through...
0
by: Michi Henning | last post by:
The help page for SocketOptionName says, toward the end: "Example The following example uses the Linger enumerated value to set the linger time of the Socket." However, the example does not...
0
by: Michi Henning | last post by:
The C# doc lists all the available SocketOptionName enumerators (on the SocketOptionName help page), but there doesn't appear to be a list of which option goes with what socket option level. It...
0
by: Kevin | last post by:
Hi, How can you set up the timeout values of the KeepAlive Socket option like you do using WSAIoctl and SIO_KEEPALIVE_VALS using C++ ? Searching about this I found several post of people using...
3
by: Ryan Liu | last post by:
Hi, I use Server: Use an endless thread to lisiten to clients requests: while(true) { TcpClient client = myListener.AcceptTcpClient();
3
by: Ryan Liu | last post by:
Hi, SocketOptionName.KeepAlive is a bool or an int value? Is it "belongs to" SocketOptionLevel.Socket? What does value 0 means? Is that meaning always "keep alive", or never "send...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.