NamedPipeClientStream.Connect 메서드

정의

대기 중인 서버에 연결합니다.

오버로드

Connect(TimeSpan)

지정된 시간 제한 기간 내에 대기 서버에 연결합니다.

Connect()

무한 시간 제한 값을 사용하여 대기 중인 서버에 연결합니다.

Connect(Int32)

지정된 시간 제한 기간 내에 대기 서버에 연결합니다.

Connect(TimeSpan)

Source:
NamedPipeClientStream.cs
Source:
NamedPipeClientStream.cs
Source:
NamedPipeClientStream.cs

지정된 시간 제한 기간 내에 대기 서버에 연결합니다.

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

매개 변수

timeout
TimeSpan

연결 시간이 초과되기 전에 서버가 응답할 때까지 대기하는 시간입니다.

설명

설명을 참조 Connect(Int32) 하세요.

적용 대상

Connect()

Source:
NamedPipeClientStream.cs
Source:
NamedPipeClientStream.cs
Source:
NamedPipeClientStream.cs

무한 시간 제한 값을 사용하여 대기 중인 서버에 연결합니다.

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

예외

클라이언트가 이미 연결되어 있습니다.

예제

다음 예제에서는 명명된 파이프를 사용하여 부모 프로세스에서 자식 프로세스로 문자열을 보내는 메서드를 보여 줍니다. 다음은 자식 프로세스에서 개체를 NamedPipeClientStream 만든 다음 로컬 컴퓨터의 파이프에 연결하는 예제입니다. 서버 예제는 클래스에서 NamedPipeServerStream 볼 수 있습니다. 이 예제는 및 NamedPipeClientStream 클래스에 대해 제공되는 더 큰 예제의 NamedPipeServerStream 일부입니다.

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

설명

이 메서드는 Connect(Int32) 무한 시간 제한 값으로 메서드를 호출합니다.

이 메서드는 파이프 instance 사용할 수 있게 될 때까지 기다립니다. Connect는 개체에서 NamedPipeServerStream 가 호출되기 전에 WaitForConnection 를 반환할 수 있지만 WaitForConnection 가 반환될 때까지 Connect 반환되지 않습니다.

개체가 연결되었지만 서버가 를 호출WaitForConnection하기 전에 파이프 NamedPipeClientStream 에 기록된 모든 데이터는 에 대한 호출 WaitForConnection후 서버에서 사용할 수 있습니다.

적용 대상

Connect(Int32)

Source:
NamedPipeClientStream.cs
Source:
NamedPipeClientStream.cs
Source:
NamedPipeClientStream.cs

지정된 시간 제한 기간 내에 대기 서버에 연결합니다.

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)

매개 변수

timeout
Int32

연결 제한 시간이 초과되기 전에 서버 응답을 기다릴 시간(밀리초)입니다.

특성

예외

지정된 timeout 기간 내에 서버에 연결할 수 없는 경우

timeout이 0보다 작고 Infinite로 설정되지 않았습니다.

클라이언트가 이미 연결되어 있습니다.

서버가 다른 클라이언트에 연결되었고 시간 초과 기간이 만료 되었습니다.

설명

이 메서드는 파이프 instance 사용할 수 있게 될 때까지 기다립니다. Connect는 에서 NamedPipeServerStream가 호출되기 전에 WaitForConnection 를 반환할 수 있지만 WaitForConnection 가 반환될 때까지 Connect 반환되지 않습니다. 매개 변수를 timeoutInfinite 설정하여 무한 제한 시간 값을 지정합니다.

개체가 연결되었지만 서버가 를 호출WaitForConnection하기 전에 파이프 NamedPipeClientStream 에 기록된 모든 데이터는 에 대한 호출 WaitForConnection후 서버에서 사용할 수 있습니다.

적용 대상