Share via


SocketAddress Kelas

Definisi

Menyimpan informasi berseri dari EndPoint kelas turunan.

public ref class SocketAddress
public ref class SocketAddress : IEquatable<System::Net::SocketAddress ^>
public class SocketAddress
public class SocketAddress : IEquatable<System.Net.SocketAddress>
type SocketAddress = class
type SocketAddress = class
    interface IEquatable<SocketAddress>
Public Class SocketAddress
Public Class SocketAddress
Implements IEquatable(Of SocketAddress)
Warisan
SocketAddress
Penerapan

Contoh

Contoh berikut menunjukkan cara menggunakan SocketAddress untuk membuat serialisasi instans EndPoint kelas. Setelah serialisasi, buffer byte yang SocketAddress mendasar dari berisi semua informasi status IPEndPoint .

//Creates an IpEndPoint.
IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );

//Serializes the IPEndPoint.
SocketAddress^ socketAddress = ipLocalEndPoint->Serialize();

//Verifies that ipLocalEndPoint is now serialized by printing its contents.
Console::WriteLine( "Contents of the socketAddress are: {0}", socketAddress );
//Checks the Family property.
Console::WriteLine( "The address family of the socketAddress is: {0}", socketAddress->Family );
//Checks the underlying buffer size.
Console::WriteLine( "The size of the underlying buffer is: {0}", socketAddress->Size );

//Creates an IpEndPoint.
IPAddress ipAddress = Dns.Resolve("www.contoso.com").AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000);

//Serializes the IPEndPoint.
SocketAddress socketAddress = ipLocalEndPoint.Serialize();

//Verifies that ipLocalEndPoint is now serialized by printing its contents.
Console.WriteLine("Contents of the socketAddress are: " + socketAddress.ToString());
//Checks the Family property.
Console.WriteLine("The address family of the socketAddress is: " + socketAddress.Family.ToString());
//Checks the underlying buffer size.
Console.WriteLine("The size of the underlying buffer is: " + socketAddress.Size.ToString());
   'Creates an IpEndPoint.
   Dim ipAddress As IPAddress = Dns.Resolve("www.contoso.com").AddressList(0)
   Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 11000)
   
   'Serializes the IPEndPoint. 
   Dim socketAddress As SocketAddress = ipLocalEndPoint.Serialize()
   
   'Verifies that ipLocalEndPoint is now serialized by printing its contents.
   Console.WriteLine(("Contents of socketAddress are: " + socketAddress.ToString()))
   'Checks the Family property.
   Console.WriteLine(("The address family of socketAddress is: " + socketAddress.Family.ToString()))
   'Checks the underlying buffer size.
   Console.WriteLine(("The size of the underlying buffer is: " + socketAddress.Size.ToString()))
End Sub

Keterangan

2 byte pertama dari buffer yang mendasar dicadangkan untuk AddressFamily nilai enumerasi. SocketAddress Ketika digunakan untuk menyimpan byte serial IPEndPoint, byte ketiga dan keempat digunakan untuk menyimpan informasi nomor port. Byte berikutnya digunakan untuk menyimpan alamat IP. Anda dapat mengakses informasi apa pun dalam buffer byte yang mendasar ini dengan merujuk ke posisi indeksnya; buffer byte menggunakan pengindeksan berbasis nol. Anda juga dapat menggunakan Family properti dan Size untuk mendapatkan AddressFamily nilai dan ukuran buffer. Untuk melihat salah satu informasi ini sebagai string, gunakan ToString metode .

Konstruktor

SocketAddress(AddressFamily)

Membuat instans SocketAddress baru kelas untuk keluarga alamat yang diberikan.

SocketAddress(AddressFamily, Int32)

Membuat instans SocketAddress baru kelas menggunakan keluarga alamat dan ukuran buffer yang ditentukan.

Properti

Buffer

Mendapatkan memori yang mendasar yang dapat diteruskan ke panggilan OS asli.

Family

AddressFamily Mendapatkan nilai enumerasi dari saat iniSocketAddress.

Item[Int32]

Mendapatkan atau mengatur elemen indeks yang ditentukan dalam buffer yang mendasar.

Size

Mendapatkan ukuran buffer yang mendasar dari SocketAddress.

Metode

Equals(Object)

Menentukan apakah yang ditentukan Object sama dengan saat ini Object.

Equals(SocketAddress)

Menunjukkan apakah objek saat ini sama dengan objek lain dengan jenis yang sama.

GetHashCode()

Berfungsi sebagai fungsi hash untuk jenis tertentu, cocok untuk digunakan dalam algoritma hash dan struktur data seperti tabel hash.

GetMaximumAddressSize(AddressFamily)

Mendapatkan ukuran buffer maksimum yang diperlukan untuk yang diberikan AddressFamily.

GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan informasi tentang alamat soket.

Berlaku untuk