Socket Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Implements the Berkeley sockets interface.

Inheritance Hierarchy

System. . :: . .Object
  System.Net.Sockets..::..Socket

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

Syntax

'Declaration
Public Class Socket _
    Implements IDisposable
public class Socket : IDisposable
public ref class Socket : IDisposable
type Socket =  
    class
        interface IDisposable
    end
public class Socket implements IDisposable

The Socket type exposes the following members.

Constructors

  Name Description
Public method Socket Initializes a new instance of the Socket class using the specified address family, socket type and protocol.

Top

Properties

  Name Description
Public property Available Gets the amount of data that has been received from the network and is available to be read.
Public property LocalEndPoint Gets the local endpoint.
Public property ReceiveTimeout Gets or sets a value that specifies the amount of time after which a synchronous Receive call will time out.
Public property RemoteEndPoint Gets the remote endpoint.
Public property SendTimeout Gets or sets a value that specifies the amount of time after which a synchronous Send call will time out.

Top

Methods

  Name Description
Public method Accept Creates a new Socket for a newly created connection.
Public method Bind Associates a Socket with a local endpoint.
Public method Close Closes the Socket connection and releases all associated resources.
Public method Connect Establishes a connection to a remote host.
Protected method Dispose Releases the unmanaged resources used by the Socket, and optionally disposes of the managed resources.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Frees resources used by the Socket class. (Overrides Object. . :: . .Finalize() () () ().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetSocketOption(SocketOptionLevel, SocketOptionName) Returns the value of a specified Socket option, represented as an object.
Public method GetSocketOption(SocketOptionLevel, SocketOptionName, array<Byte> [] () [] []) Returns the specified Socket option setting, represented as a byte array.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Listen Places a Socket in a listening state.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Poll Determines the status of the Socket.
Public method Receive(array<Byte> [] () [] []) Receives data from a bound Socket into a receive buffer.
Public method Receive(array<Byte> [] () [] [], SocketFlags) Receives data from a bound Socket into a receive buffer, using the specified SocketFlags.
Public method Receive(array<Byte> [] () [] [], Int32, SocketFlags) Receives the specified number of bytes of data from a bound Socket into a receive buffer, using the specified SocketFlags.
Public method Receive(array<Byte> [] () [] [], Int32, Int32, SocketFlags) Receives the specified number of bytes from a bound Socket into the specified offset position of the receive buffer, using the specified SocketFlags.
Public method ReceiveFrom(array<Byte> [] () [] [], EndPoint%) Receives a datagram into the data buffer and stores the endpoint.
Public method ReceiveFrom(array<Byte> [] () [] [], SocketFlags, EndPoint%) Receives a datagram into the data buffer, using the specified SocketFlags, and stores the endpoint.
Public method ReceiveFrom(array<Byte> [] () [] [], Int32, SocketFlags, EndPoint%) Receives the specified number of bytes into the data buffer, using the specified SocketFlags, and stores the endpoint.
Public method ReceiveFrom(array<Byte> [] () [] [], Int32, Int32, SocketFlags, EndPoint%) Receives the specified number of bytes of data into the specified location of the data buffer, using the specified SocketFlags, and stores the endpoint.
Public method Send(array<Byte> [] () [] []) Sends data to a connected Socket.
Public method Send(array<Byte> [] () [] [], SocketFlags) Sends data to a connected Socket using the specified SocketFlags.
Public method Send(array<Byte> [] () [] [], Int32, SocketFlags) Sends the specified number of bytes of data to a connected Socket, using the specified SocketFlags.
Public method Send(array<Byte> [] () [] [], Int32, Int32, SocketFlags) Sends the specified number of bytes of data to a connected Socket, starting at the specified offset, and using the specified SocketFlags.
Public method SendTo(array<Byte> [] () [] [], EndPoint) Sends data to the specified endpoint.
Public method SendTo(array<Byte> [] () [] [], SocketFlags, EndPoint) Sends data to a specific endpoint using the specified SocketFlags.
Public method SendTo(array<Byte> [] () [] [], Int32, SocketFlags, EndPoint) Sends the specified number of bytes of data to the specified endpoint using the specified SocketFlags.
Public method SendTo(array<Byte> [] () [] [], Int32, Int32, SocketFlags, EndPoint) Sends the specified number of bytes of data to the specified endpoint, starting at the specified location in the buffer, and using the specified SocketFlags.
Public method SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean) Sets the specified Socket option to the specified Boolean value.
Public method SetSocketOption(SocketOptionLevel, SocketOptionName, array<Byte> [] () [] []) Sets the specified Socket option to the specified value, represented as a byte array.
Public method SetSocketOption(SocketOptionLevel, SocketOptionName, Int32) Sets the specified Socket option to the specified integer value.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IDisposable. . :: . .Dispose Infrastructure. Releases all resources used by the Socket.

Top

Remarks

The Socket class provides a rich set of methods and properties for network communications. The Socket class allows you to perform both synchronous and asynchronous data transfer using any of the communication protocols listed in the ProtocolType enumeration.

The Socket class allows you to configure your Socket using the SetSocketOption method. Retrieve these settings using the GetSocketOption method.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Net.Sockets Namespace