Remoting in C# and .NET - The Journal of Object Technology
Remoting in C# and .NET - The Journal of Object Technology
Remoting in C# and .NET - The Journal of Object Technology
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
REMOTING IN <strong>C#</strong> AND .<strong>NET</strong>}}}<strong>Remot<strong>in</strong>g</strong>Configuration.RegisterWellKnownServiceType(type<strong>of</strong>(ChatServer),"ChatServer",WellKnown<strong>Object</strong>Mode.S<strong>in</strong>gleton);Console.WriteL<strong>in</strong>e("Press return to exit ChatServer.");Console.ReadL<strong>in</strong>e();Discussion <strong>and</strong> Analysis <strong>of</strong> List<strong>in</strong>g 3<strong>The</strong> ChatServer class holds two serializable fields, clients, an ArrayList, <strong>and</strong> chatSession,a Str<strong>in</strong>g.<strong>The</strong> ChatClient class is more complex because <strong>of</strong> the GUI. It conta<strong>in</strong>s a server field<strong>of</strong> type ChatServer. When each client application is launched, a comm<strong>and</strong>-l<strong>in</strong>e argument(str<strong>in</strong>g) that conta<strong>in</strong>s the name <strong>of</strong> the client (Richard <strong>and</strong> Erik <strong>in</strong> the example above) mustbe supplied to the program. This important identification is the only means that clientshave to know who is logged-on <strong>and</strong> who they can “talk” to.When the user clicks the “Log<strong>in</strong>” button, code that enables the client to be connectedto the server <strong>and</strong> the server object activated is executed. S<strong>in</strong>ce the server object is as<strong>in</strong>gleton, its state is ma<strong>in</strong>ta<strong>in</strong>ed between calls from various clients.All calls to the remote server object are shown <strong>in</strong> blue. MarshalByRef<strong>Object</strong> is usedto ensure that <strong>in</strong>formation is transmitted to the server through a proxy throughserialization <strong>and</strong> not by value. If marshal by value were used (by remov<strong>in</strong>g the<strong>in</strong>heritance from class MarshalByRef<strong>Object</strong>), each client would have its own <strong>in</strong>dependentcopy <strong>of</strong> the server object <strong>and</strong> would not be updated when another client added text orremoved itself from the system.About the authorRichard Wiener is Associate Pr<strong>of</strong>essor <strong>of</strong> Computer Science at theUniversity <strong>of</strong> Colorado at Colorado Spr<strong>in</strong>gs. He is also the Editor-<strong>in</strong>-Chief <strong>of</strong> JOT <strong>and</strong> former Editor-<strong>in</strong>-Chief <strong>of</strong> the <strong>Journal</strong> <strong>of</strong> <strong>Object</strong>Oriented Programm<strong>in</strong>g. In addition to University work, Dr. Wiener hasauthored or co-authored 21 books <strong>and</strong> works actively as a consultant<strong>and</strong> s<strong>of</strong>tware contractor whenever the possibility arises.100 JOURNAL OF OBJECT TECHNOLOGY VOL. 3, NO. 1