System.Net.SocketAddress Class

public class SocketAddress

Base Types

Object
  SocketAddress

Assembly

System

Library

Networking

Summary

Provides a socket address stored in a Byte array.

Description

At a minimum, a socket address consists of a member of the AddressFamily enumeration stored in the first two bytes of the array.

Attributes

DefaultMemberAttribute("Item")

See Also

System.Net Namespace

Members

SocketAddress Constructors

SocketAddress(System.Net.Sockets.AddressFamily) Constructor
SocketAddress(System.Net.Sockets.AddressFamily, int) Constructor

SocketAddress Methods

SocketAddress.Equals Method
SocketAddress.GetHashCode Method
SocketAddress.ToString Method

SocketAddress Properties

SocketAddress.Family Property
SocketAddress.Item Property
SocketAddress.Size Property


SocketAddress(System.Net.Sockets.AddressFamily) Constructor

public SocketAddress(AddressFamily family);

Summary

Constructs and initializes a new instance of the SocketAddress class.

Parameters

family
One of the values of the AddressFamily enumeration.

Description

This method is equivalent to System.Net.SocketAddress.SocketAddress(family, 32).

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress(System.Net.Sockets.AddressFamily, int) Constructor

public SocketAddress(AddressFamily family, int size);

Summary

Constructs and initializes a new instance of the SocketAddress class.

Parameters

family
One of the values of the AddressFamily enumeration.
size
A Int32 containing the number of bytes to allocate for the Byte array storing the socket address.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionsize is less than 2.

Description

The minimum value for size is 2 bytes.

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress.Equals Method

public override bool Equals(object comparand);

Summary

Determines whether the current instance and the specified Object represent the same socket address.

Parameters

comparand
The Object to compare to the current instance.

Return Value

A Boolean where true indicates comparand is an instance of the SocketAddress class and contains the same data as the current instance; otherwise false .

Description

[Note: This method overrides System.Object.Equals(System.Object).

]

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for the current instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.

]

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress.ToString Method

public override string ToString();

Summary

Returns a String representation of the value of the current instance.

Return Value

A String representation of the current instance.

Description

The returned string contains the string representation of the address family, the length of the array holding the socket address, and the contents of the array from the third to the maximum element, output in the following format:

System.Net.SocketAddress.Family:System.Net.SocketAddress.Size:{array[2], array[3], ..., element[Size - 1]}

[Note: This method overrides System.Object.ToString.

]

Example

The following example writes a socket address to the console.

using System;
using System.Net;
using System.Net.Sockets;

public class SocketAddressToString{
  public static void Main() {
    Console.WriteLine("This is a minimal SocketAddress.");
    SocketAddress socketAddress = new 
           SocketAddress(AddressFamily.InterNetwork);
    Console.WriteLine("{0}", socketAddress.ToString());
  }
}
   
The output is

This is a minimal SocketAddress.

InterNetwork:32:{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress.Family Property

public AddressFamily Family { get; }

Summary

Gets the address family which specifies the addressing scheme used to resolve an address.

Property Value

One of the values defined in the AddressFamily enumeration.

Description

This property is read-only.

This property is set by the SocketAddress constructors and is stored in the first two bytes of the socket address array.

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress.Item Property

public byte this[int offset] { get; set; }

Summary

Gets or sets the element at the specified index of the Byte array storing the socket address.

Parameters

offset
A Int32 containing the zero-based index of the element to get or set.

Property Value

A Byte containing the element at the specified index.

Exceptions

Exception TypeCondition
IndexOutOfRangeExceptionoffset is < 0.

-or-

offset >= System.Net.SocketAddress.Size.

See Also

System.Net.SocketAddress Class, System.Net Namespace

SocketAddress.Size Property

public int Size { get; }

Summary

Gets the length of the socket address.

Property Value

A Int32 containing the length of the Byte array storing the socket address.

Description

This property is read-only.

This property is set by the SocketAddress constructors.

See Also

System.Net.SocketAddress Class, System.Net Namespace