本文整理汇总了C#中System.Net.Sockets.MulticastOption.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MulticastOption.ToString方法的具体用法?C# MulticastOption.ToString怎么用?C# MulticastOption.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.MulticastOption
的用法示例。
在下文中一共展示了MulticastOption.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setMulticastOption
private void setMulticastOption(SocketOptionName optionName, MulticastOption MR) {
IPMulticastRequest ipmr = new IPMulticastRequest();
ipmr.MulticastAddress = unchecked((int)MR.Group.m_Address);
if(MR.LocalAddress != null){
ipmr.InterfaceAddress = unchecked((int)MR.LocalAddress.m_Address);
}
else { //this structure works w/ interfaces as well
int ifIndex =IPAddress.HostToNetworkOrder(MR.InterfaceIndex);
ipmr.InterfaceAddress = unchecked((int)ifIndex);
}
#if BIGENDIAN
ipmr.MulticastAddress = (int) (((uint) ipmr.MulticastAddress << 24) |
(((uint) ipmr.MulticastAddress & 0x0000FF00) << 8) |
(((uint) ipmr.MulticastAddress >> 8) & 0x0000FF00) |
((uint) ipmr.MulticastAddress >> 24));
if(MR.LocalAddress != null){
ipmr.InterfaceAddress = (int) (((uint) ipmr.InterfaceAddress << 24) |
(((uint) ipmr.InterfaceAddress & 0x0000FF00) << 8) |
(((uint) ipmr.InterfaceAddress >> 8) & 0x0000FF00) |
((uint) ipmr.InterfaceAddress >> 24));
}
#endif // BIGENDIAN
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPMulticastRequest.Size:" + IPMulticastRequest.Size.ToString());
// This can throw ObjectDisposedException.
SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
SocketOptionLevel.IP,
optionName,
ref ipmr,
IPMulticastRequest.Size);
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption() UnsafeNclNativeMethods.OSSOCK.setsockopt returns errorCode:" + errorCode);
//
// if the native call fails we'll throw a SocketException
//
if (errorCode==SocketError.SocketError) {
//
// update our internal state after this socket error and throw
//
SocketException socketException = new SocketException();
UpdateStatusAfterSocketError(socketException);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "setMulticastOption", socketException);
throw socketException;
}
}
示例2: setMulticastOption
private void setMulticastOption(SocketOptionName optionName, MulticastOption MR) {
IPMulticastRequest ipmr = new IPMulticastRequest();
ipmr.MulticastAddress = unchecked((int)MR.Group.Address);
ipmr.InterfaceAddress = unchecked((int)MR.LocalAddress.Address);
#if BIGENDIAN
ipmr.MulticastAddress = (int) (((uint) ipmr.MulticastAddress << 24) |
(((uint) ipmr.MulticastAddress & 0x0000FF00) << 8) |
(((uint) ipmr.MulticastAddress >> 8) & 0x0000FF00) |
((uint) ipmr.MulticastAddress >> 24));
ipmr.InterfaceAddress = (int) (((uint) ipmr.InterfaceAddress << 24) |
(((uint) ipmr.InterfaceAddress & 0x0000FF00) << 8) |
(((uint) ipmr.InterfaceAddress >> 8) & 0x0000FF00) |
((uint) ipmr.InterfaceAddress >> 24));
#endif // BIGENDIAN
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPMulticastRequest.Size:" + IPMulticastRequest.Size.ToString());
int errorCode =
UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
SocketOptionLevel.IP,
optionName,
ref ipmr,
IPMulticastRequest.Size );
//
// if the native call fails we'll throw a SocketException
//
if (errorCode==SocketErrors.SocketError) {
//
// update our internal state after this socket error and throw
//
SocketException socketException = new SocketException();
UpdateStatusAfterSocketError();
throw socketException;
}
}