本文整理汇总了C#中System.Net.SocketAddress类的典型用法代码示例。如果您正苦于以下问题:C# SocketAddress类的具体用法?C# SocketAddress怎么用?C# SocketAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketAddress类属于System.Net命名空间,在下文中一共展示了SocketAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例7: AddSession
public void AddSession(SocketAddress address, Session session)
{
if (_Sessions.TryAdd(address, session))
{
_SessionsByID.TryAdd(session.SessionID, session);
_SessionList.Add(session);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}