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
|
/*
Kurze Erklärung: Das RemoteObjekt muß als Klassenbibliothek erstellt werden und unter Verweise beim Server sowie beim Client hinzugefügt sein.
*/
//Hier wird der Server Beschrieben
using System;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using System.Security.Permissions;
public class Servers
{
[SecurityPermission(SecurityAction.Demand)]
public static void Main(string[] args)
{
// Erstellen eines Channel
IpcChannel serverChannel = new IpcChannel("localhost:9091");
// Registriert denn Channal zum Server
ChannelServices.RegisterChannel(serverChannel);
// Stellt das Objekt für denn registrierten Channal bereit.
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "RemoteObject.rem",
WellKnownObjectMode.Singleton);
Console.WriteLine("Drück ENTER zum Beenden des Server.");
Console.ReadLine();
Console.WriteLine("Server schließt.");
}
}
//Hier wird der Client beschrieben.
using System;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
public class Client
{
[SecurityPermission(SecurityAction.Demand)]
public static void Main(string[] args)
{
IpcChannel channel = new IpcChannel();
// Registrieren des Channel.
ChannelServices.RegisterChannel(channel);
// Registrieren als Client für das Remote Objekt.
WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
typeof(RemoteObject),
"ipc://localhost:9091/RemoteObject.rem");
RemotingConfiguration.RegisterWellKnownClientType(remoteType);
// Anlegen einer Instance für das Remote Objekt.
RemoteObject service = new RemoteObject();
Console.WriteLine("Das Objekt wurde {0} mal aufgerufen.", service.GetCount());
Console.ReadLine();
}
}
// Remote Objekt.
using System;
public class RemoteObject : MarshalByRefObject
{
private int callCount = 0;
public int GetCount()
{
Console.WriteLine("GetCount wurde aufgerufen.");
callCount++;
return(callCount);
}
}
|