NegotiateStream.Write(Byte[], Int32, Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したバッファーとオフセットを使用して、指定した数の Byteを基になるストリームに書き込みます。
public:
override void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public override void Write(byte[] buffer, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, count As Integer)
パラメーター
例外
buffer は nullです。
offset が 0 未満です。
-または-
offset が bufferの長さを超えています。
-または-
offset プラス数が bufferの長さを超えています。
書き込み操作は既に進行中です。
このオブジェクトは閉じられています。
認証が行われません。
例
次のコード例は、 NegotiateStreamへの書き込みを示しています。
public static void Main(String[] args)
{
// Establish the remote endpoint for the socket.
// For this example, use the local machine.
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
// Client and server use port 11000.
IPEndPoint remoteEP = new IPEndPoint(ipAddress,11000);
// Create a TCP/IP socket.
TcpClient client = new TcpClient();
// Connect the socket to the remote endpoint.
client.Connect(remoteEP);
Console.WriteLine("Client connected to {0}.",
remoteEP.ToString());
// Ensure the client does not close when there is
// still data to be sent to the server.
client.LingerState = (new LingerOption(true,0));
// Request authentication.
NetworkStream clientStream = client.GetStream();
NegotiateStream authStream = new NegotiateStream(clientStream);
// Request authentication for the client only (no mutual authentication).
// Authenicate using the client's default credetials.
// Permit the server to impersonate the client to access resources on the server only.
// Request that data be transmitted using encryption and data signing.
authStream.AuthenticateAsClient(
(NetworkCredential) CredentialCache.DefaultCredentials,
"",
ProtectionLevel.EncryptAndSign,
TokenImpersonationLevel.Impersonation);
DisplayAuthenticationProperties(authStream);
DisplayStreamProperties(authStream);
if (authStream.CanWrite)
{
// Encode the test data into a byte array.
byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello from the client.");
authStream.Write(message, 0, message.Length);
authStream.Flush();
Console.WriteLine("Sent {0} bytes.", message.Length);
}
// Close the client connection.
authStream.Close();
Console.WriteLine("Client closed.");
}
注釈
暗号化、署名、または暗号化と署名が有効になっている場合、このメソッドはバッファーからデータを読み取り、暗号化、署名、または署名を行い、基になるストリームを使用して送信します。 データ暗号化や署名などのセキュリティ サービスが使用されていない場合、このメソッドは基になるストリームで Write を呼び出します。
このメソッドは、書き込み操作の完了中にブロックします。 操作の完了中にブロックされないようにするには、 WriteAsync メソッドを使用します。
正常に認証されるまで、このメソッドを呼び出すことはできません。 認証するには、 AuthenticateAsClient、 AuthenticateAsClientAsync、 BeginAuthenticateAsClient、 AuthenticateAsServer、 AuthenticateAsServerAsync、または BeginAuthenticateAsServer のいずれかのメソッドを呼び出します。
NegotiateStream クラスは、複数の同時書き込み操作をサポートしていません。 別の書き込み操作が同じストリームで既に実行されている間に書き込み操作を開始しようとすると、 NotSupportedException 例外がスローされます。