本文整理汇总了C#中System.Net.SocketAddress类的典型用法代码示例。如果您正苦于以下问题:C# SocketAddress类的具体用法?C# SocketAddress怎么用?C# SocketAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketAddress类属于System.Net命名空间,在下文中一共展示了SocketAddress类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: UnixDomainSocketEndPoint
internal UnixDomainSocketEndPoint(SocketAddress socketAddress)
{
if (socketAddress == null)
{
throw new ArgumentNullException(nameof(socketAddress));
}
if (socketAddress.Family != EndPointAddressFamily ||
socketAddress.Size > s_nativeAddressSize)
{
throw new ArgumentOutOfRangeException(nameof(socketAddress));
}
if (socketAddress.Size > s_nativePathOffset)
{
_encodedPath = new byte[socketAddress.Size - s_nativePathOffset];
for (int i = 0; i < _encodedPath.Length; i++)
{
_encodedPath[i] = socketAddress[s_nativePathOffset + i];
}
_path = s_pathEncoding.GetString(_encodedPath, 0, _encodedPath.Length);
}
else
{
#if NET451
_encodedPath = new byte[0];
#else
_encodedPath = Array.Empty<byte>();
#endif
_path = string.Empty;
}
}
开发者ID:Christiestporter,项目名称:JavaScriptServices,代码行数:33,代码来源:UnixDomainSocketEndPoint.cs
示例2: Remove
public void Remove(Session session, SocketAddress address)
{
Session existing;
_Sessions.TryRemove(address, out session);
_SessionsByID.TryRemove(session.SessionID, out existing);
_SessionList.Remove(session);
}
开发者ID:CreatorDev,项目名称:DTLS.Net,代码行数:7,代码来源:Sessions.cs
示例3: Create
public override EndPoint Create (SocketAddress socketAddress)
{
/*
* Should also check this
*
int addr = (int) AddressFamily.Unix;
if (socketAddress [0] != (addr & 0xFF))
throw new ArgumentException ("socketAddress is not a unix socket address.");
if (socketAddress [1] != ((addr & 0xFF00) >> 8))
throw new ArgumentException ("socketAddress is not a unix socket address.");
*/
if (socketAddress.Size == 2) {
// Empty filename.
// Probably from RemoteEndPoint which on linux does not return the file name.
UnixEndPoint uep = new UnixEndPoint ("a");
uep.filename = "";
return uep;
}
int size = socketAddress.Size - 2;
byte [] bytes = new byte [size];
for (int i = 0; i < bytes.Length; i++) {
bytes [i] = socketAddress [i + 2];
// There may be junk after the null terminator, so ignore it all.
if (bytes [i] == 0) {
size = i;
break;
}
}
string name = Encoding.Default.GetString (bytes, 0, size);
return new UnixEndPoint (name);
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:34,代码来源:UnixEndPoint.cs
示例4: Create
public override EndPoint Create (SocketAddress socketAddress)
{
/*
* Should also check this
*
int addr = (int) AddressFamily.Unix;
if (socketAddress [0] != (addr & 0xFF))
throw new ArgumentException ("socketAddress is not a unix socket address.");
if (socketAddress [1] != ((addr & 0xFF00) >> 8))
throw new ArgumentException ("socketAddress is not a unix socket address.");
*/
if (socketAddress.Size == 2) {
// Empty filename.
// Probably from RemoteEndPoint which on linux does not return the file name.
UnixEndPoint uep = new UnixEndPoint ("a");
uep.filename = "";
return uep;
}
byte [] bytes = new byte [socketAddress.Size - 2 - 1];
for (int i = 0; i < bytes.Length; i++) {
bytes [i] = socketAddress [i + 2];
}
string name = Encoding.Default.GetString (bytes);
return new UnixEndPoint (name);
}
开发者ID:xzkmxd,项目名称:mono,代码行数:28,代码来源:UnixEndPoint.cs
示例5: Serialize
public override SocketAddress Serialize()
{
if (this.m_Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
SocketAddress address = new SocketAddress(this.AddressFamily, 0x1c);
int port = this.Port;
address[2] = (byte) (port >> 8);
address[3] = (byte) port;
address[4] = 0;
address[5] = 0;
address[6] = 0;
address[7] = 0;
long scopeId = this.Address.ScopeId;
address[0x18] = (byte) scopeId;
address[0x19] = (byte) (scopeId >> 8);
address[0x1a] = (byte) (scopeId >> 0x10);
address[0x1b] = (byte) (scopeId >> 0x18);
byte[] addressBytes = this.Address.GetAddressBytes();
for (int i = 0; i < addressBytes.Length; i++)
{
address[8 + i] = addressBytes[i];
}
return address;
}
SocketAddress address2 = new SocketAddress(this.m_Address.AddressFamily, 0x10);
address2[2] = (byte) (this.Port >> 8);
address2[3] = (byte) this.Port;
address2[4] = (byte) this.Address.m_Address;
address2[5] = (byte) (this.Address.m_Address >> 8);
address2[6] = (byte) (this.Address.m_Address >> 0x10);
address2[7] = (byte) (this.Address.m_Address >> 0x18);
return address2;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:IPEndPoint.cs
示例6: Create
public override EndPoint Create(SocketAddress socketAddress)
{
// strip out of SocketAddress information on the EndPoint
//
byte[] buf = socketAddress.m_Buffer;
Debug.Assert(socketAddress.Family == AddressFamily.InterNetwork);
int port = (int)(
(buf[2] << 8 & 0xFF00) |
(buf[3])
);
long address = (long)(
(buf[4] & 0x000000FF) |
(buf[5] << 8 & 0x0000FF00) |
(buf[6] << 16 & 0x00FF0000) |
(buf[7] << 24)
) & 0x00000000FFFFFFFF;
IPEndPoint created = new IPEndPoint(address, port);
return created;
}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:25,代码来源:IPEndPoint.cs
示例7: AddSession
public void AddSession(SocketAddress address, Session session)
{
if (_Sessions.TryAdd(address, session))
{
_SessionsByID.TryAdd(session.SessionID, session);
_SessionList.Add(session);
}
}
开发者ID:CreatorDev,项目名称:DTLS.Net,代码行数:8,代码来源:Sessions.cs
示例8: SetUnmanagedStructures
//
// SetUnmanagedStructures -
// Fills in Overlapped Structures used in an Async Overlapped Winsock call
// these calls are outside the runtime and are unmanaged code, so we need
// to prepare specific structures and ints that lie in unmanaged memory
// since the Overlapped calls can be Async
//
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, SocketAddress socketAddress, SocketFlags socketFlags)
{
m_MessageBuffer = new byte[s_WSAMsgSize];
m_WSABufferArray = new byte[s_WSABufferSize];
//ipv4 or ipv6?
IPAddress ipAddress = (socketAddress.Family == AddressFamily.InterNetworkV6
? socketAddress.GetIPAddress() : null);
bool ipv4 = (((Socket)AsyncObject).AddressFamily == AddressFamily.InterNetwork
|| (ipAddress != null && ipAddress.IsIPv4MappedToIPv6)); // DualMode
bool ipv6 = ((Socket)AsyncObject).AddressFamily == AddressFamily.InterNetworkV6;
//prepare control buffer
if (ipv4) {
m_ControlBuffer = new byte[s_ControlDataSize];
}
else if (ipv6) {
m_ControlBuffer = new byte[s_ControlDataIPv6Size];
}
//pin buffers
object[] objectsToPin = new object[(m_ControlBuffer != null)?5:4];
objectsToPin[0] = buffer;
objectsToPin[1] = m_MessageBuffer;
objectsToPin[2] = m_WSABufferArray;
//prepare socketaddress buffer
m_SocketAddress = socketAddress;
m_SocketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[3] = m_SocketAddress.m_Buffer;
if(m_ControlBuffer != null){
objectsToPin[4] = m_ControlBuffer;
}
base.SetUnmanagedStructures(objectsToPin);
//prepare data buffer
m_WSABuffer = (WSABuffer*) Marshal.UnsafeAddrOfPinnedArrayElement(m_WSABufferArray, 0);
m_WSABuffer->Length = size;
m_WSABuffer->Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
//setup structure
m_Message = (UnsafeNclNativeMethods.OSSOCK.WSAMsg*) Marshal.UnsafeAddrOfPinnedArrayElement(m_MessageBuffer, 0);
m_Message->socketAddress = Marshal.UnsafeAddrOfPinnedArrayElement(m_SocketAddress.m_Buffer,0);
m_Message->addressLength = (uint)m_SocketAddress.Size;
m_Message->buffers = Marshal.UnsafeAddrOfPinnedArrayElement(m_WSABufferArray,0);
m_Message->count = 1;
if(m_ControlBuffer != null){
m_Message->controlBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(m_ControlBuffer, 0);
m_Message->controlBuffer.Length = m_ControlBuffer.Length;
}
m_Message->flags = socketFlags;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:65,代码来源:_ReceiveMessageOverlappedAsyncResult.cs
示例9: Create
virtual public EndPoint Create(SocketAddress socketAddress)
{
Contract.Requires(socketAddress.Family == this.AddressFamily);
Contract.Requires(socketAddress.Size >= 8);
Contract.Ensures(Contract.Result<EndPoint>()!= null);
return default(EndPoint);
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:9,代码来源:System.Net.IPEndPoint.cs
示例10: Serialize
public override SocketAddress Serialize ()
{
byte [] bytes = Encoding.Default.GetBytes (filename);
SocketAddress sa = new SocketAddress (AddressFamily, bytes.Length + 2);
// sa [0] -> family low byte, sa [1] -> family high byte
for (int i = 0; i < bytes.Length; i++)
sa [i + 2] = bytes [i];
return sa;
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:UnixEndPoint.cs
示例11: RecvFrom_internal
private static int RecvFrom_internal(IntPtr sock,
byte[] buffer,
int offset,
int count,
SocketFlags flags,
ref SocketAddress sockaddr,
out int error)
{
throw new System.NotImplementedException();
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:10,代码来源:Socket.Mosa.cs
示例12: GetBestInterfaceForAddress
private static int GetBestInterfaceForAddress(IPAddress addr) {
int index;
SocketAddress address = new SocketAddress(addr);
int error = (int)UnsafeNetInfoNativeMethods.GetBestInterfaceEx(address.m_Buffer, out index);
if (error != 0) {
throw new NetworkInformationException(error);
}
return index;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:10,代码来源:SystemNetworkInterface.cs
示例13: Rtp
public Rtp()
{
RtpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
SocketAddress sa = new SocketAddress(AddressFamily.InterNetwork);
IPEndPoint ep = new IPEndPoint(IPAddress.Any, RtpPort);
RtpSocket.Bind(ep);
//IPEndPoint iep = (IPEndPoint)RtpSocket.LocalEndPoint;
//ClientPort = iep.Port;
//Logging.Log(string.Format("Ip Address {0}, Port {1}", iep.Address.ToString(), ClientPort));
RtpEvntArgs = new SocketAsyncEventArgs();
RtpEvntArgs.Completed += RtpEvntArgs_Completed;
}
开发者ID:ahmeda8,项目名称:wp8-rtsp-rtp-latm,代码行数:12,代码来源:Rtp.cs
示例14: Serialize
public override SocketAddress Serialize()
{
var result = new SocketAddress(AddressFamily.Unix, s_nativeAddressSize);
for (int index = 0; index < _encodedPath.Length; index++)
{
result[s_nativePathOffset + index] = _encodedPath[index];
}
result[s_nativePathOffset + _encodedPath.Length] = 0; // path must be null-terminated
return result;
}
开发者ID:Christiestporter,项目名称:JavaScriptServices,代码行数:12,代码来源:UnixDomainSocketEndPoint.cs
示例15: ReadIPEndPoint
public IPEndPoint ReadIPEndPoint()
{
SocketAddress socketAddress = new SocketAddress(AddressFamily.InterNetwork);
byte[] socketAddressBytes = ReadBytes(28);
for (int i = 0; i < socketAddressBytes.Length; i++)
{
socketAddress[i] = socketAddressBytes[i];
}
return (IPEndPoint)new IPEndPoint(IPAddress.Any, 0).Create(socketAddress);
}
开发者ID:puppt,项目名称:GW2Emu,代码行数:12,代码来源:Deserializer.cs
示例16: Serialize
public override SocketAddress Serialize()
{
// we add a byte (0 = raw, 1 = tls) to the SocketAddress generated by the base
var tmp = base.Serialize();
int count = tmp.Size;
var sockAddr = new SocketAddress(this.AddressFamily, count + 1);
for(int i=0;i<count;i++) sockAddr[i] = tmp[i];
sockAddr[count] = m_tls ? (byte)1 : (byte)0;
return sockAddr;
}
开发者ID:rektide,项目名称:foundationdb-dotnet-client,代码行数:14,代码来源:FdbEndPoint.cs
示例17: Create
public override EndPoint Create(SocketAddress sockaddr) {
if (sockaddr.Size < 8) {
return null;
}
if (sockaddr.Family != AddressFamily.InterNetwork) {
// Only support IP4
return null;
}
int port = (((int)sockaddr[2]) << 8) | (int)sockaddr[3];
long address = (((long)sockaddr[7]) << 24) |
(((long)sockaddr[6]) << 16) |
(((long)sockaddr[5]) << 8) |
(long)sockaddr[4];
return new IPEndPoint(address, port);
}
开发者ID:bradparks,项目名称:DotNetAnywhere,代码行数:15,代码来源:IPEndPoint.cs
示例18: GetHostEntry
public static IPHostEntry GetHostEntry(string hostNameOrAddress)
{
//Do we need to try to pase this as an Address????
string canonicalName;
byte[][] addresses;
NativeSocket.getaddrinfo(hostNameOrAddress, out canonicalName, out addresses);
int cAddresses = addresses.Length;
IPAddress[] ipAddresses = new IPAddress[cAddresses];
IPHostEntry ipHostEntry = new IPHostEntry();
for (int i = 0; i < cAddresses; i++)
{
byte[] address = addresses[i];
SocketAddress sockAddress = new SocketAddress(address);
AddressFamily family;
if(SystemInfo.IsBigEndian)
{
family = (AddressFamily)((address[0] << 8) | address[1]);
}
else
{
family = (AddressFamily)((address[1] << 8) | address[0]);
}
//port address[2-3]
if (family == AddressFamily.InterNetwork)
{
//This only works with IPv4 addresses
uint ipAddr = (uint)((address[7] << 24) | (address[6] << 16) | (address[5] << 8) | (address[4]));
ipAddresses[i] = new IPAddress((long)ipAddr);
}
}
ipHostEntry.hostName = canonicalName;
ipHostEntry.addressList = ipAddresses;
return ipHostEntry;
}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:46,代码来源:DNS.cs
示例19: Create
public override EndPoint Create(SocketAddress socketAddress)
{
//note: this methods constructs a NEW endpoint, and does not change the current instance (why???)
// Current implementation of IPEndPoint does really check the exact size of the buffer, and should not use the extra byte we added...
// > Fix this if this is no longer the case in future .NET implementations (or Mono?)
var tmp = (IPEndPoint)base.Create(socketAddress);
bool tls = false;
int count = socketAddress.Size;
if ((socketAddress.Family == System.Net.Sockets.AddressFamily.InterNetwork && count == 17) || (socketAddress.Family == System.Net.Sockets.AddressFamily.InterNetworkV6 && count == 29))
{
tls = socketAddress[count - 1] != 0;
}
return new FdbEndPoint(tmp.Address, tmp.Port, tls);
}
开发者ID:rektide,项目名称:foundationdb-dotnet-client,代码行数:17,代码来源:FdbEndPoint.cs
示例20: Create
public override EndPoint Create(SocketAddress SockAddr)
{
if (SockAddr == null ||
SockAddr.Family != AF_HYPERV ||
SockAddr.Size != 34)
{
return null;
}
HyperVSocketEndPoint endpoint = new HyperVSocketEndPoint(SockAddr.Family, Guid.Empty, Guid.Empty);
string sockAddress = SockAddr.ToString();
endpoint.VmId = new Guid(sockAddress.Substring(4, 16));
endpoint.ServiceId = new Guid(sockAddress.Substring(20, 16));
return endpoint;
}
开发者ID:40a,项目名称:PowerShell,代码行数:18,代码来源:RemoteSessionHyperVSocket.cs
注:本文中的System.Net.SocketAddress类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论