13.07.2015 Views

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

SHOW MORE
SHOW LESS

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>}if (dispos<strong>in</strong>g) {if (components != null) {components.Dispose();}}base.Dispose(dispos<strong>in</strong>g);}}private void OnPa<strong>in</strong>t(<strong>Object</strong> sender, Pa<strong>in</strong>tEventArgs e) {Graphics g = e.Graphics;g.DrawRectangle(new Pen(new SolidBrush(Color.Blue)),server.XPOS, server.YPOS, 50, 50);if (server.X != 0 && server.Y != 0) {g.DrawStr<strong>in</strong>g("x", Font,new SolidBrush(Color.Red), server.X, server.Y);}}private void InitializeComponent() {// Details not shown}[STAThread]static void Ma<strong>in</strong>() {Application.Run(new Client2());}Discussion <strong>and</strong> Analysis <strong>of</strong> List<strong>in</strong>g 2<strong>The</strong> TargetServer spawns a thread <strong>and</strong> starts creat<strong>in</strong>g xPos <strong>and</strong> yPos values every twoseconds. <strong>The</strong> Client1 application communicates with this server through the Recordmethod. Because the TargetServer is declared a subclass <strong>of</strong> MarshalByRef<strong>Object</strong>,communication through proxy objects is accomplished for both Client1 <strong>and</strong> Client2. Each<strong>of</strong> these GUI applications holds a reference to this proxy object as a server field.Chat Session Application<strong>The</strong> f<strong>in</strong>al application is a simple chat client/server application.Any number <strong>of</strong> client applications, each conta<strong>in</strong><strong>in</strong>g a GUI that allows text to beadded to the exist<strong>in</strong>g session, should permit communication among all clients that havelogged <strong>in</strong>. All clients are updated on all communications every second.<strong>The</strong> application is designed so that each client must know about the server, but theserver does not know about any <strong>of</strong> the clients. <strong>The</strong> server’s responsibility is to ma<strong>in</strong>ta<strong>in</strong> acentralized store <strong>of</strong> the clients that are logged <strong>in</strong> as well as the text for the entire chatsession by add<strong>in</strong>g text to it whenever a client posts a new message by click<strong>in</strong>g the “SendText” button.94 JOURNAL OF OBJECT TECHNOLOGY VOL. 3, NO. 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!