Guest User

Untitled

a guest
Jul 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.Remoting;
  5. using System.Runtime.Remoting.Channels;
  6. using System.Runtime.Remoting.Channels.Ipc;
  7. using System.Runtime.Remoting.Channels.Tcp;
  8. using System.Text;
  9.  
  10.  
  11. namespace moa.test.remote.client {
  12.  
  13.  
  14. using moa.test.remote;
  15.  
  16.  
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. class RemoteClient {
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. public RemoteClient() {
  25. }
  26.  
  27.  
  28. /// <summary>
  29. /// クライアント用 RemoteScreenObject を生成します。
  30. /// </summary>
  31. /// <param name="server">リモート接続するサーバ名。</param>
  32. /// <param name="obj_name">対象のオブジェクト名。</param>
  33. /// <param name="obj_type">対象のオブジェクトタイプ。</param>
  34. /// <returns>アクティベートされたリモートオブジェクト。</returns>
  35. public object createRemoteScreenObject(string server,
  36. string obj_name,
  37. Type obj_type
  38. ) {
  39. Hashtable channel_config = new Hashtable();
  40.  
  41. channel_config["name"] = "ipc server";
  42. channel_config["portName"] = server;
  43. channel_config["secure"] = true;
  44.  
  45. IChannel channel = new IpcServerChannel( channel_config, null );
  46. ChannelServices.RegisterChannel( channel, true );
  47.  
  48. string url = string.Format( "ipc://{0}/{1}/", server, obj_name );
  49.  
  50. return Activator.GetObject( obj_type, url );
  51. }
  52. /// <summary>
  53. /// クライアント用 RemoteScreenObject を生成します。
  54. /// </summary>
  55. /// <param name="server">リモート接続するサーバ名。</param>
  56. /// <param name="port">使用するポート番号。</param>
  57. /// <param name="obj_name">対象のオブジェクト名。</param>
  58. /// <param name="obj_type">対象のオブジェクトタイプ。</param>
  59. /// <returns>アクティベートされたリモートオブジェクト。</returns>
  60. public object createRemoteScreenObject(string server,
  61. int port,
  62. string obj_name,
  63. Type obj_type
  64. ) {
  65. Hashtable channel_config = new Hashtable();
  66.  
  67. channel_config.Add( "name", string.Empty ); // 匿名チャネル
  68. channel_config.Add( "authenticationMode", obj_name );
  69. channel_config.Add( "secure", true );
  70.  
  71. // クライアントチャネルを登録します。
  72. //TcpClientChannel channel = new TcpClientChannel( channel_config, null );
  73. IChannel channel = new TcpServerChannel( "", 0 );
  74. ChannelServices.RegisterChannel( channel, false );
  75.  
  76. // リモートオブジェクトを生成します。
  77. object result = Activator.GetObject( obj_type,
  78. string.Format( "tcp://{0}:{1}/{2}",
  79. server,
  80. port,
  81. obj_name
  82. )
  83. );
  84. return result;
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment