IpcChannel 클래스

정의

IPC 프로토콜을 사용하여 메시지를 전송하는 채널을 구현합니다.

public ref class IpcChannel : System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class IpcChannel : System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type IpcChannel = class
    interface IChannelReceiver
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
type IpcChannel = class
    interface IChannelReceiver
    interface IChannel
    interface IChannelSender
    interface ISecurableChannel
Public Class IpcChannel
Implements IChannelReceiver, IChannelSender, ISecurableChannel
상속
IpcChannel
구현

예제

다음 코드 예제를 사용 하는 방법을 보여 줍니다는 IpcChannel 원격 서버 및 클라이언트를 설정 합니다. 예제에서는 세 부분이 포함 됩니다.

  • 서버

  • 클라이언트

  • 서버 및 클라이언트에서 사용하는 원격 개체입니다.

다음 코드 예제에서는 서버를 나타냅니다.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"
using namespace System;
using namespace System::Runtime::Remoting::Channels::Ipc;

void main()
{
   // Create the server channel.
   IpcChannel^ serverChannel = gcnew IpcChannel( L"localhost:9090" );

   // Register the server channel.
   System::Runtime::Remoting::Channels::ChannelServices::RegisterChannel( serverChannel );

   // Show the name of the channel.
   Console::WriteLine( L"The name of the channel is {0}.", serverChannel->ChannelName );

   // Show the priority of the channel.
   Console::WriteLine( L"The priority of the channel is {0}.", serverChannel->ChannelPriority );

   // Show the URIs associated with the channel.
   System::Runtime::Remoting::Channels::ChannelDataStore^ channelData = (System::Runtime::Remoting::Channels::ChannelDataStore^)serverChannel->ChannelData;
   for each (String^ uri in channelData->ChannelUris)
   {
      Console::WriteLine("The channel URI is {0}.", uri);
   }
   
   // Expose an object for remote calls.
   System::Runtime::Remoting::RemotingConfiguration::RegisterWellKnownServiceType(
         RemoteObject::typeid,L"RemoteObject.rem",
         System::Runtime::Remoting::WellKnownObjectMode::Singleton);
   
   // Parse the channel's URI.
   array<String^>^ urls = serverChannel->GetUrlsForUri( L"RemoteObject.rem" );
   if ( urls->Length > 0 )
   {
      String^ objectUrl = urls[ 0 ];
      String^ objectUri;
      String^ channelUri = serverChannel->Parse( objectUrl,  objectUri );
      Console::WriteLine( L"The object URI is {0}.", objectUri );
      Console::WriteLine( L"The channel URI is {0}.", channelUri );
      Console::WriteLine( L"The object URL is {0}.", objectUrl );
   }

   // Wait for the user prompt.
   Console::WriteLine( L"Press ENTER to exit the server." );
   Console::ReadLine();
   Console::WriteLine( L"The server is exiting." );
}
using System;
using System.Runtime.Remoting.Channels.Ipc;

public class Server
{
    public static void Main(string[] args)
    {
        // Create the server channel.
        IpcChannel serverChannel =
            new IpcChannel("localhost:9090");

        // Register the server channel.
        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(
            serverChannel);

        // Show the name of the channel.
        Console.WriteLine("The name of the channel is {0}.",
            serverChannel.ChannelName);

        // Show the priority of the channel.
        Console.WriteLine("The priority of the channel is {0}.",
            serverChannel.ChannelPriority);

        // Show the URIs associated with the channel.
        System.Runtime.Remoting.Channels.ChannelDataStore channelData =
            (System.Runtime.Remoting.Channels.ChannelDataStore)
            serverChannel.ChannelData;
        foreach (string uri in channelData.ChannelUris)
        {
            Console.WriteLine("The channel URI is {0}.", uri);
        }

        // Expose an object for remote calls.
        System.Runtime.Remoting.RemotingConfiguration.
            RegisterWellKnownServiceType(
                typeof(RemoteObject), "RemoteObject.rem",
                System.Runtime.Remoting.WellKnownObjectMode.Singleton);

        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri = serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
        }

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
}

다음 코드 예제에서는이 서버에 대 한 클라이언트를 보여 줍니다.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"
using namespace System;
using namespace System::Runtime::Remoting::Channels::Ipc;

void main()
{
   
   // Create the channel.
   IpcChannel^ channel = gcnew IpcChannel;
   
   // Register the channel.
   System::Runtime::Remoting::Channels::ChannelServices::RegisterChannel(channel);
   
   // Register as client for remote object.
   System::Runtime::Remoting::WellKnownClientTypeEntry^ remoteType = gcnew
       System::Runtime::Remoting::WellKnownClientTypeEntry( 
         RemoteObject::typeid,L"ipc://localhost:9090/RemoteObject.rem" );
   System::Runtime::Remoting::RemotingConfiguration::RegisterWellKnownClientType(remoteType);
   
   // Create a message sink.
   String^ objectUri;
   System::Runtime::Remoting::Messaging::IMessageSink^ messageSink = channel->CreateMessageSink(
      L"ipc://localhost:9090/RemoteObject.rem", nullptr, objectUri );
   Console::WriteLine( L"The URI of the message sink is {0}.", objectUri );
   if ( messageSink != nullptr )
   {
      Console::WriteLine( L"The type of the message sink is {0}.", messageSink->GetType() );
   }

   
   // Create an instance of the remote object.
   RemoteObject^ service = gcnew RemoteObject;
   
   // Invoke a method on the remote object.
   Console::WriteLine( L"The client is invoking the remote object." );
   Console::WriteLine( L"The remote object has been called {0} times.", service->GetCount() );
}
using System;
using System.Runtime.Remoting.Channels.Ipc;

public class Client
{
    public static void Main(string[] args)
    {
        // Create the channel.
        IpcChannel channel = new IpcChannel();

        // Register the channel.
        System.Runtime.Remoting.Channels.ChannelServices.
            RegisterChannel(channel);

        // Register as client for remote object.
        System.Runtime.Remoting.WellKnownClientTypeEntry remoteType =
            new System.Runtime.Remoting.WellKnownClientTypeEntry(
                typeof(RemoteObject),
                "ipc://localhost:9090/RemoteObject.rem");
        System.Runtime.Remoting.RemotingConfiguration.
            RegisterWellKnownClientType(remoteType);

        // Create a message sink.
        string objectUri;
        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            channel.CreateMessageSink(
                "ipc://localhost:9090/RemoteObject.rem", null,
                out objectUri);
        Console.WriteLine("The URI of the message sink is {0}.",
            objectUri);
        if (messageSink != null)
        {
            Console.WriteLine("The type of the message sink is {0}.",
                messageSink.GetType().ToString());
        }

        // Create an instance of the remote object.
        RemoteObject service = new RemoteObject();

        // Invoke a method on the remote object.
        Console.WriteLine("The client is invoking the remote object.");
        Console.WriteLine("The remote object has been called {0} times.",
            service.GetCount());
    }
}

다음 코드 예제는 서버와 클라이언트에서 사용 하는 원격 개체를 보여 줍니다.

using namespace System;

// Remote object.
public ref class RemoteObject: public MarshalByRefObject
{
private:
   static int callCount = 0;

public:
   int GetCount()
   {
      Console::WriteLine( L"GetCount has been called." );
      callCount++;
      return (callCount);
   }

};
using System;

// Remote object.
public class RemoteObject : MarshalByRefObject
{
    private int callCount = 0;

    public int GetCount()
    {
        Console.WriteLine("GetCount has been called.");
        callCount++;
        return(callCount);
    }
}

설명

중요

신뢰할 수 없는 데이터로 이 클래스에서 메서드를 호출하는 것은 보안상 위험합니다. 신뢰할 수 있는 데이터로만 이 클래스에서 메서드를 호출하세요. 자세한 내용은 모든 입력 유효성 검사를 참조하세요.

채널은 원격 호출을 전송 하기 the.NET Framework 원격 인프라에서 사용 됩니다. 클라이언트가 원격 개체를 호출 하면 호출 클라이언트 채널에서 전송 및 서버 채널에서 수신 되는 메시지로 serialize 됩니다. 메시지를 받은 후 역직렬화하 처리 합니다. 반환 된 값 서버 채널에서 전송 되며 클라이언트 채널에서 수신 됩니다.

합니다 IpcChannel 클래스는 편의 클래스의 기능을 결합 합니다 IpcClientChannel 클래스 및 IpcServerChannel 클래스입니다.

주의

설정 하는 경우는 exclusiveAddressUse 속성을 falseproperties 인수를 여러 IpcServerChannel 동일한 명명 된 파이프에 대 한 개체를 등록할 수 있습니다. 이러한 경우 요청 수 등록 된 채널 중 하나로 이동 합니다. 이 설정은 alc가 사용 되는 경우에 안전 합니다.

생성자

IpcChannel()

서버 채널은 활성화하지 않고 클라이언트 채널만 활성화하는 IpcChannel 클래스의 새 인스턴스를 초기화합니다.

IpcChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

지정된 구성 속성 및 싱크를 사용하여 IpcChannel 클래스의 새 인스턴스를 초기화합니다.

IpcChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider, CommonSecurityDescriptor)

지정된 구성 속성 및 싱크를 사용하여 IpcChannel 클래스의 새 인스턴스를 초기화합니다.

IpcChannel(String)

지정된 IPC 포트에서 수신을 대기하는 서버 채널을 사용하여 IpcChannel 클래스의 새 인스턴스를 초기화합니다.

속성

ChannelData

채널 관련 데이터를 가져옵니다.

ChannelName

현재 채널의 이름을 가져옵니다.

ChannelPriority

현재 채널의 우선 순위를 가져옵니다.

IsSecured

현재 채널이 보안 채널인지 여부를 나타내는 부울 값을 가져오거나 설정합니다.

메서드

CreateMessageSink(String, Object, String)

지정된 URL이나 채널 데이터 개체에 메시지를 보내는 채널 메시지 싱크를 반환합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
GetUrlsForUri(String)

현재 IpcChannel에 호스팅된 지정된 URI를 사용하는 개체에 대한 모든 URL 배열을 반환합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Parse(String, String)

지정된 URL에서 채널 URI와 잘 알려진 원격 개체 URI를 추출합니다.

StartListening(Object)

현재 채널에게 요청 수신을 시작하도록 지시합니다.

StopListening(Object)

현재 채널에게 요청 수신을 중지하도록 지시합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상