NetworkStream Constructors

Definition

Creates a new instance of the NetworkStream class.

Overloads

NetworkStream(Socket)

Creates a new instance of the NetworkStream class for the specified Socket.

NetworkStream(Socket, Boolean)

Initializes a new instance of the NetworkStream class for the specified Socket with the specified Socket ownership.

NetworkStream(Socket, FileAccess)

Creates a new instance of the NetworkStream class for the specified Socket with the specified access rights.

NetworkStream(Socket, FileAccess, Boolean)

Creates a new instance of the NetworkStream class for the specified Socket with the specified access rights and the specified Socket ownership.

NetworkStream(Socket)

Creates a new instance of the NetworkStream class for the specified Socket.

public:
 NetworkStream(System::Net::Sockets::Socket ^ socket);
public NetworkStream (System.Net.Sockets.Socket socket);
new System.Net.Sockets.NetworkStream : System.Net.Sockets.Socket -> System.Net.Sockets.NetworkStream
Public Sub New (socket As Socket)

Parameters

socket
Socket

The Socket that the NetworkStream will use to send and receive data.

Exceptions

The socket parameter is null.

The socket parameter is not connected.

-or-

The SocketType property of the socket parameter is not Stream.

-or-

The socket parameter is in a nonblocking state.

Remarks

The NetworkStream is created with read/write access to the specified Socket. The NetworkStream does not own the underlying Socket, so calling the Close or Dispose method does not close the Socket.

See also

Applies to

NetworkStream(Socket, Boolean)

Initializes a new instance of the NetworkStream class for the specified Socket with the specified Socket ownership.

public:
 NetworkStream(System::Net::Sockets::Socket ^ socket, bool ownsSocket);
public NetworkStream (System.Net.Sockets.Socket socket, bool ownsSocket);
new System.Net.Sockets.NetworkStream : System.Net.Sockets.Socket * bool -> System.Net.Sockets.NetworkStream
Public Sub New (socket As Socket, ownsSocket As Boolean)

Parameters

socket
Socket

The Socket that the NetworkStream will use to send and receive data.

ownsSocket
Boolean

Set to true to indicate that the NetworkStream will take ownership of the Socket; otherwise, false.

Exceptions

The socket parameter is null.

The socket parameter is not connected.

-or-

the value of the SocketType property of the socket parameter is not Stream.

-or-

the socket parameter is in a nonblocking state.

Remarks

The NetworkStream is created with read/write access to the specified Socket. If the value of ownsSocket parameter is true, the NetworkStream takes ownership of the underlying Socket, and calling the Close or Dispose method also closes the underlying Socket.

See also

Applies to

NetworkStream(Socket, FileAccess)

Creates a new instance of the NetworkStream class for the specified Socket with the specified access rights.

public:
 NetworkStream(System::Net::Sockets::Socket ^ socket, System::IO::FileAccess access);
public NetworkStream (System.Net.Sockets.Socket socket, System.IO.FileAccess access);
new System.Net.Sockets.NetworkStream : System.Net.Sockets.Socket * System.IO.FileAccess -> System.Net.Sockets.NetworkStream
Public Sub New (socket As Socket, access As FileAccess)

Parameters

socket
Socket

The Socket that the NetworkStream will use to send and receive data.

access
FileAccess

A bitwise combination of the FileAccess values that specify the type of access given to the NetworkStream over the provided Socket.

Exceptions

The socket parameter is null.

The socket parameter is not connected.

-or-

the SocketType property of the socket parameter is not Stream.

-or-

the socket parameter is in a nonblocking state.

Remarks

The NetworkStream is created with the specified access to the specified Socket. With this constructor, the NetworkStream does not own the underlying Socket, so calling the Close or Dispose method does not close the underlying Socket.

The access parameter sets the CanRead and CanWrite properties of the NetworkStream. If you specify Write, then the NetworkStream allows calls to the Write method. If you specify Read, then the NetworkStream allows calls to the Read method. If you specify ReadWrite, both method calls are allowed.

See also

Applies to

NetworkStream(Socket, FileAccess, Boolean)

Creates a new instance of the NetworkStream class for the specified Socket with the specified access rights and the specified Socket ownership.

public:
 NetworkStream(System::Net::Sockets::Socket ^ socket, System::IO::FileAccess access, bool ownsSocket);
public NetworkStream (System.Net.Sockets.Socket socket, System.IO.FileAccess access, bool ownsSocket);
new System.Net.Sockets.NetworkStream : System.Net.Sockets.Socket * System.IO.FileAccess * bool -> System.Net.Sockets.NetworkStream
Public Sub New (socket As Socket, access As FileAccess, ownsSocket As Boolean)

Parameters

socket
Socket

The Socket that the NetworkStream will use to send and receive data.

access
FileAccess

A bitwise combination of the FileAccess values that specifies the type of access given to the NetworkStream over the provided Socket.

ownsSocket
Boolean

Set to true to indicate that the NetworkStream will take ownership of the Socket; otherwise, false.

Exceptions

The socket parameter is null.

The socket parameter is not connected.

-or-

The SocketType property of the socket parameter is not Stream.

-or-

The socket parameter is in a nonblocking state.

Remarks

The NetworkStream is created with read/write access to the specified Socket. If the value of the ownsSocket parameter is true, the NetworkStream takes ownership of the underlying Socket, and calling the Close or Dispose method also closes the underlying Socket.

The access parameter sets the CanRead and CanWrite properties of the NetworkStream. If you specify Write, then the NetworkStream allows calls to the Write method. If you specify Read, then the NetworkStream allows calls to the Read method. If you specify ReadWrite, both method calls are allowed.

See also

Applies to