Notice
Recent Posts
Recent Comments
관리 메뉴

안까먹을라고 쓰는 블로그

[C#] IPC / RPC 통신 본문

Language/C#

[C#] IPC / RPC 통신

YawnsDuzin 2012. 10. 29. 15:36

 

반응형
네임스페이스 : System.Runtime.Remoting.Channels.Ipc
                   System.Runtime.Remoting.Channels.Http
어셈블리 : System.Runtime.Remoting(System.Runtime.Remoting.dll)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Runtime.Remoting.Channels.Ipc;                    // IPC
using System.Runtime.Remoting.Channels.Http;                   // RPC
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using prjRemote_Object;
 
 
// IPC Server Initial
RemoteObject  ro = new RemoteObject();
// Create the server channel.
IpcClientChannel ClientChannel = new IpcClientChannel();
// Register the server channel.
ChannelServices.RegisterChannel(ClientChannel, false);
// Expose an object for remote calls.
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject), "ipc://remote/Cnt");
// IPC Client Initial
RemoteObject ro = new RemoteObject();
// Create the client channel.
IpcClientChannel ClientChannel = new IpcClientChannel();
// Register the client channel.
ChannelServices.RegisterChannel(ClientChannel, false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject), "ipc://remote/Cnt");
 
 
// RPC Server Initial
RemoteObject ro = new RemoteObject();
// Create the server channel.
HttpServerChannel ServerChannel = new HttpServerChannel(9090);
// Register the server channel.
ChannelServices.RegisterChannel(ServerChannel, false);
// Expose an object for remote calls.
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "RemoteObject.rem", WellKnownObjectMode.Singleton);
// RPC Client Initial
RemoteObject ro = new RemoteObject();
// Create the client channel.
HttpClientChannel ClientChannel = new HttpClientChannel();
// Register the server channel.
ChannelServices.RegisterChannel(ClientChannel, false);
// Register as client for remote object.
WellKnownClientTypeEntry RemoteType = new WellKnownClientTypeEntry(typeof(RemoteObject), "http://192.168.0.16:9090/RemoteObject.rem");
RemotingConfiguration.RegisterWellKnownClientType(RemoteType);
 
 
// Channel Status Check
// Create a message sink.
string objectUri;
System.Runtime.Remoting.Messaging.IMessageSink messageSink =
ClientChannel.CreateMessageSink("http://localhost:9090/RemoteObject.rem"nullout objectUri);
this.textBox1.AppendText("The URI of the message sink is " + objectUri);
if (messageSink != null)
{
this.textBox1.AppendText("The type of the message sink is " + messageSink.GetType().ToString() +   
                                      Environment.NewLine);
}
 
// Display the channel's properties using Keys and Item.
foreach (string key in ClientChannel.Keys)
{
this.textBox1.AppendText("clientChannel[" + key + "] = <" + ClientChannel[key] + ">" + Environment.NewLine);
}
 
// Parse the channel's URI.
string objectUrl = "http://localhost:9090/RemoteObject.rem";
string channelUri = ClientChannel.Parse(objectUrl, out objectUri);
this.textBox1.AppendText("The object URL is " + objectUrl + Environment.NewLine);
this.textBox1.AppendText("The object URI is " + objectUri + Environment.NewLine);
this.textBox1.AppendText("The channel URI is " + channelUri + Environment.NewLine);
 
// Create an instance of the remote object.
RemoteObject service = new RemoteObject();
 
// Invoke a method on the remote object.
this.textBox1.AppendText("The client is invoking the remote object." + Environment.NewLine);
this.textBox1.AppendText("The remote object has been called " + service.GetCount() + " times." +
Environment.NewLine);
 
 
// prjRPC_RemoteObject
using System;
 
namespace prjRPC_RemoteObject
{
    public class RemoteObject : MarshalByRefObject
    {
        private static int Count = 0;
 
        public int GetCount()
        {
            return (Count);
        }
 
        public void SetCount(int cnt)
        {
            Count = cnt;
        }
    }
}
 
 
// Get / Set Method
ro.GetCount();
ro.SetCount()
cs

[.Net Remotinghttp://blog.naver.com/ingodl00?Redirect=Log&logNo=57302629


반응형

'Language > C#' 카테고리의 다른 글

[C#] INI 읽고/쓰기  (0) 2012.12.10
[C#] 부모폼과 자식폼의 참조  (0) 2012.10.30
[C#] IPC(Inter Process Communication) - 프로세스간 통신  (0) 2012.10.29
[C#] Timer 배열로 사용하기  (0) 2012.10.05
[C#] Network Ping Test  (0) 2012.09.11
Comments