Net Remoting Jim Fawcett CSE 681 Software Modeling
- Slides: 17
. Net Remoting Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
References n n Programming Microsoft. Net, Jeff Prosise, Microsoft Press, 2002, Chap 15. http: //samples. gotdotnet. com/quickstart/howto/ 2
. Net Remoting n Remoting supports a client’s invocation of an object on a remote machine. q The server acts as a host for the remote object, loading it into memory and servicing client requests on a worker thread spawned by the server process’s main thread. n q All of this is transparent to the designer. The client makes calls as if the object were instantiated on the local machine. 3
Remoting Architecture 4
Server Supporting Remote-able Object n Class of Remote-able object is derived from Marshal. By. Ref. Object. q n Server: q q n Otherwise the object is oblivious of the remoting infrastructure. creates a Tcp. Server. Channel Registers Channel with Channel. Services Registers Class of remote-able object with Remoting. Configuration Then main server thread waits for client to shut it down. This can be done either programmatically or with a config file. We will demonstrate the former. 5
Client of Remote-able Object n Client: q q Creates Tcp. Client. Channel Registers channel with Channel. Services Creates a proxy for remote object by calling Activator. Get. Object Uses proxy to invoke remote object: string ret. Val = clnt. proxy. say(msg); 6
Remoting Server Code static void Main(string[] args) { Tcp. Server. Channel chan = new Tcp. Server. Channel(8085); Channel. Services. Register. Channel(chan); Remoting. Configuration. Register. Well. Known. Service. Type( typeof(Hello), // type of the remote object "Hello. Obj", Well. Known. Object. Mode. Singleton ); System. Console. Write. Line("n Hit <enter> to exit. . . "); System. Console. Read. Line(); } 7
Remotable Object Code public class Hello : Marshal. By. Ref. Object { private int count = 0; public Hello() { Console. Write. Line(" construction of Hello Object"); } public string say(string s) { ++count; Console. Write. Line(" " + s); string rtn. Msg = “remote object received message #”; rtn. Msg += count. To. String(); return (rtn. Msg); } } 8
Client Code class client { private Hello proxy; //----< set up TCP channel >---------------void Set. Up. Channel() { Tcp. Client. Channel chan = new Tcp. Client. Channel(); Channel. Services. Register. Channel(chan); } //----< activate remote object and return proxy >-----void Activate. Remote. Object() { proxy = (Hello)Activator. Get. Object( typeof(Hello), "tcp: //localhost: 8085/Hello. Obj" ); if(proxy == null) Console. Write. Line("can't activate object"); } 9
static void Main(string[] args) { client clnt = new client(); clnt. Set. Up. Channel(); clnt. Activate. Remote. Object(); if (clnt. proxy == null) { System. Console. Write. Line(" -- Could not locate server -- "); return; } Console. Write("n To call remote object enter string"); Console. Write. Line("n Just hit enter to quit: "); try { while(true) { string test = ". . . "; Console. Write("n > "); test = Console. Read. Line(); if(test == "") break; // invoke remote object string ret. Val = clnt. proxy. say(test); // display string returned from remote object Console. Write(" "); Console. Write(ret. Val); } } catch(System. Exception e) { Console. Write. Line(e. Message); } } 10
11
Message Passing n Remoting can be used to construct a message-passing system with very little code. q q Use a remote-able object for server-side processing. The client main thread creates a child thread to handle sending and receiving messages. n n n The client threads share two First-In-First-Out (FIFO) queues. To make a request of the server, the client main thread composes a request message and posts it to a send. Q shared with the child thread. The child thread de. Qs the message and sends it as a parameter in a call to the remote server object. When the server processing is complete, the server’s response message is returned to the child thread. The child thread posts the return value to the Recv. Q. The client main tread dequeues the response for processing. 12
Message Passing Architecture 13
Multiple Clients n Remote-able objects have one of two activation attributes: q q n Singlecall each client gets a new copy of the remote-able object on its own child thread. Singleton All clients get a reference to the same remote-able object operating on the only child thread. Message-passing systems will usually want to use singlecall remote-able objects. 14
Multiple Clients 15
Other Topics n Prosise discusses: q q q Asynchronous method calls Handling remote events with delegates Declarative configuration (using config files) Client activated remote objects Leases control lifetime of singleton and client activated objects. IIS activation and HTTP channels 16
. Net Remoting The End 17
- 681 complex inc
- 681 complex inc
- Cs 681
- What is 239 rounded to the nearest hundred
- Helen erickson biography
- Dimensional modeling vs relational modeling
- Margerie bonner
- Example of coercion
- Brian fawcett
- Where was hamilton born
- Philippa fawcett
- Barry fawcett
- Dennis fawcett
- Dr richard fawcett
- Graham fawcett
- Fawcett definition
- Barry fawcett
- Dr jonathan fawcett