NamedPipeClientStream.Connect Método

Definição

Conecta-se a um servidor de espera.Connects to a waiting server.

Sobrecargas

Connect()

Conecta a um servidor de espera com um valor de tempo limite infinito.Connects to a waiting server with an infinite time-out value.

Connect(Int32)

Conecta a um servidor de espera dentro do período de tempo limite especificado.Connects to a waiting server within the specified time-out period.

Connect()

Conecta a um servidor de espera com um valor de tempo limite infinito.Connects to a waiting server with an infinite time-out value.

public:
 void Connect();
public void Connect ();
member this.Connect : unit -> unit
Public Sub Connect ()

Exceções

O cliente já está conectado.The client is already connected.

Exemplos

O exemplo a seguir demonstra um método para enviar uma cadeia de caracteres de um processo pai para um processo filho usando pipes nomeados.The following example demonstrates a method to send a string from a parent process to a child process using named pipes. Este exemplo cria um NamedPipeClientStream objeto em um processo filho que, em seguida, se conecta a um pipe no computador local.This example creates a NamedPipeClientStream object in a child process, which then connects to a pipe on the local computer. O exemplo de servidor pode ser visto na NamedPipeServerStream classe.The server example can be seen in the NamedPipeServerStream class. Este exemplo faz parte de um exemplo maior fornecido para as NamedPipeServerStream NamedPipeClientStream classes e.This example is part of a larger example provided for the NamedPipeServerStream and NamedPipeClientStream classes.

using System;
using System.IO;
using System.IO.Pipes;

class PipeClient
{
    static void Main(string[] args)
    {
        using (NamedPipeClientStream pipeClient =
            new NamedPipeClientStream(".", "testpipe", PipeDirection.In))
        {

            // Connect to the pipe or wait until the pipe is available.
            Console.Write("Attempting to connect to pipe...");
            pipeClient.Connect();

            Console.WriteLine("Connected to pipe.");
            Console.WriteLine("There are currently {0} pipe server instances open.",
               pipeClient.NumberOfServerInstances);
            using (StreamReader sr = new StreamReader(pipeClient))
            {
                // Display the read text to the console
                string temp;
                while ((temp = sr.ReadLine()) != null)
                {
                    Console.WriteLine("Received from server: {0}", temp);
                }
            }
        }
        Console.Write("Press Enter to continue...");
        Console.ReadLine();
    }
}
Imports System.IO
Imports System.IO.Pipes
Imports System.Security.Principal

Class PipeClient

    Shared Sub Main(ByVal args As String())

        Dim pipeClient As New NamedPipeClientStream("localhost", _
                    "testpipe", PipeDirection.In, PipeOptions.None)

        ' Connect to the pipe or wait until the pipe is available.
        Console.WriteLine("Attempting to connect to the pipe...")
        pipeClient.Connect()

        Console.WriteLine("Connect to the pipe.")
        Console.WriteLine("There are currently {0} pipe server instances open.", _
                          pipeClient.NumberOfServerInstances)

        Dim sr As New StreamReader(pipeClient)
        Dim temp As String

        temp = sr.ReadLine()
        While Not temp Is Nothing
            Console.WriteLine("Received from server: {0}", temp)
            temp = sr.ReadLine()
        End While
        Console.Write("Press Enter to continue...")
        Console.ReadLine()
    End Sub
End Class

Comentários

Esse método chama o Connect(Int32) método com um valor de tempo limite infinito.This method calls the Connect(Int32) method with an infinite time-out value.

Esse método espera que uma instância de pipe fique disponível.This method waits for a pipe instance to become available. Connect pode retornar antes WaitForConnection é chamado a partir do NamedPipeServerStream objeto, mas WaitForConnection não retornará até que Connect tenha retornado.Connect might return before WaitForConnection is called from the NamedPipeServerStream object, but WaitForConnection will not return until Connect has returned.

Todos os dados gravados no pipe após a conexão de um NamedPipeClientStream objeto, mas antes do servidor WaitForConnection ser chamado, estarão disponíveis para o servidor após a chamada para WaitForConnection .Any data written to the pipe after a NamedPipeClientStream object has connected, but before the server has called WaitForConnection, will be available to the server following the call to WaitForConnection.

Aplica-se a

Connect(Int32)

Conecta a um servidor de espera dentro do período de tempo limite especificado.Connects to a waiting server within the specified time-out period.

public:
 void Connect(int timeout);
public void Connect (int timeout);
[System.Security.SecurityCritical]
public void Connect (int timeout);
member this.Connect : int -> unit
[<System.Security.SecurityCritical>]
member this.Connect : int -> unit
Public Sub Connect (timeout As Integer)

Parâmetros

timeout
Int32

O número de milissegundos a se aguardar a resposta do servidor antes da conexão expirar.The number of milliseconds to wait for the server to respond before the connection times out.

Atributos

Exceções

Não foi possível se conectar ao servidor no período timeout especificado.Could not connect to the server within the specified timeout period.

timeout é menor que 0 e não é definido como Infinite.timeout is less than 0 and not set to Infinite.

O cliente já está conectado.The client is already connected.

O servidor está conectado a outro cliente e o período de tempo limite expirou.The server is connected to another client and the time-out period has expired.

Comentários

Esse método espera que uma instância de pipe fique disponível.This method waits for a pipe instance to become available. Connect pode retornar antes WaitForConnection é chamado a partir de NamedPipeServerStream , mas WaitForConnection não retornará até que Connect tenha retornado.Connect might return before WaitForConnection is called from the NamedPipeServerStream, but WaitForConnection will not return until Connect has returned. Defina o timeout parâmetro como Infinite para especificar um valor de tempo limite infinito.You set the timeout parameter to Infinite to specify an infinite time-out value.

Todos os dados gravados no pipe após a conexão de um NamedPipeClientStream objeto, mas antes do servidor WaitForConnection ser chamado, estarão disponíveis para o servidor após a chamada para WaitForConnection .Any data written to the pipe after a NamedPipeClientStream object has connected, but before the server has called WaitForConnection, will be available to the server following the call to WaitForConnection.

Aplica-se a