Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.Remoting;
- using System.Runtime.Remoting.Channels;
- using System.Runtime.Remoting.Channels.Ipc;
- using System.Runtime.Remoting.Channels.Tcp;
- using System.Text;
- namespace moa.test.remote.client {
- using moa.test.remote;
- /// <summary>
- ///
- /// </summary>
- class RemoteClient {
- /// <summary>
- ///
- /// </summary>
- public RemoteClient() {
- }
- /// <summary>
- /// クライアント用 RemoteScreenObject を生成します。
- /// </summary>
- /// <param name="server">リモート接続するサーバ名。</param>
- /// <param name="obj_name">対象のオブジェクト名。</param>
- /// <param name="obj_type">対象のオブジェクトタイプ。</param>
- /// <returns>アクティベートされたリモートオブジェクト。</returns>
- public object createRemoteScreenObject(string server,
- string obj_name,
- Type obj_type
- ) {
- Hashtable channel_config = new Hashtable();
- channel_config["name"] = "ipc server";
- channel_config["portName"] = server;
- channel_config["secure"] = true;
- IChannel channel = new IpcServerChannel( channel_config, null );
- ChannelServices.RegisterChannel( channel, true );
- string url = string.Format( "ipc://{0}/{1}/", server, obj_name );
- return Activator.GetObject( obj_type, url );
- }
- /// <summary>
- /// クライアント用 RemoteScreenObject を生成します。
- /// </summary>
- /// <param name="server">リモート接続するサーバ名。</param>
- /// <param name="port">使用するポート番号。</param>
- /// <param name="obj_name">対象のオブジェクト名。</param>
- /// <param name="obj_type">対象のオブジェクトタイプ。</param>
- /// <returns>アクティベートされたリモートオブジェクト。</returns>
- public object createRemoteScreenObject(string server,
- int port,
- string obj_name,
- Type obj_type
- ) {
- Hashtable channel_config = new Hashtable();
- channel_config.Add( "name", string.Empty ); // 匿名チャネル
- channel_config.Add( "authenticationMode", obj_name );
- channel_config.Add( "secure", true );
- // クライアントチャネルを登録します。
- //TcpClientChannel channel = new TcpClientChannel( channel_config, null );
- IChannel channel = new TcpServerChannel( "", 0 );
- ChannelServices.RegisterChannel( channel, false );
- // リモートオブジェクトを生成します。
- object result = Activator.GetObject( obj_type,
- string.Format( "tcp://{0}:{1}/{2}",
- server,
- port,
- obj_name
- )
- );
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment