'Net Remoting - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

'Net Remoting

Description:

set up TCP channel - void SetUpChannel() TcpClientChannel chan = new TcpClientChannel ... One object accepts a string message and enqueues it on a receive ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 13
Provided by: jimfa
Category:
Tags: net | remoting | setup

less

Transcript and Presenter's Notes

Title: 'Net Remoting


1
.Net Remoting
  • Jim Fawcett
  • CSE691/891 Internet Programming
  • Summer 2002

2
.Net Remoting
  • Remoting supports a clients invocation of an
    object on a remote machine.
  • 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
    processs main thread.
  • 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
  • Class of Remote-able object is derived from
    MarshalByRefObject.
  • Otherwise the object is oblivious of the remoting
    infrastructure.
  • Server
  • creates a TcpServerChannel
  • Registers Channel with ChannelServices
  • Registers Class of remote-able object with
    RemotingConfiguration
  • Then server waits for client to shut it down.

5
Client of Remote-able Object
  • Client
  • Creates TcpClientChannel
  • Registers channel with ChannelServices
  • Creates a proxy for remote object by calling
    Activator.GetObject
  • Uses proxy to invoke remote object string
    retVal clnt.proxy.say(msg)

6
Remoting Server Code
  • static void Main(string args)
  • TcpServerChannel chan new TcpServerChannel(80
    85)
  • ChannelServices.RegisterChannel(chan)
  • RemotingConfiguration.RegisterWellKnownServiceT
    ype(
  • typeof(Hello), // type of the remote object
  • "HelloObj",
  • WellKnownObjectMode.Singleton
  • )
  • System.Console.WriteLine("\n Hit ltentergt to
    exit...")
  • System.Console.ReadLine()

7
Remotable Object Code
  • public class Hello MarshalByRefObject
  • private int count 0
  • public Hello()
  • Console.WriteLine(" construction of Hello
    Object")
  • public string say(string s)
  • count
  • Console.WriteLine(" " s)
  • string rtnMsg remote object received
    message
  • rtnMsg count.ToString()
  • return (rtnMsg)

8
Client Code
  • class client
  • private Hello proxy
  • //----lt set up TCP channel gt------------------
    -------------
  • void SetUpChannel()
  • TcpClientChannel chan new
    TcpClientChannel()
  • ChannelServices.RegisterChannel(chan)
  • //----lt activate remote object and return
    proxy gt----------
  • void ActivateRemoteObject()
  • proxy (Hello)Activator.GetObject(
  • typeof(Hello),
  • "tcp//localhost8085/HelloObj"
  • )

9
  • static void Main(string args)
  • client clnt new client()
  • clnt.SetUpChannel()
  • clnt.ActivateRemoteObject()
  • if (clnt.proxy null)
  • System.Console.WriteLine(" -- Could not
    locate server -- ") return
  • Console.Write("\n To call remote object
    enter string")
  • Console.WriteLine("\n Just hit enter to
    quit")
  • try
  • while(true)
  • string test "..."
  • Console.Write("\n gt ")
  • test Console.ReadLine()
  • if(test "")

10
(No Transcript)
11
Message Passing
  • Remoting could used to construct a
    message-passing system with very little code.
  • Use two remote-able objects.
  • One object accepts a string message and enqueues
    it on a receive queue, for access by the main
    server thread.
  • The other object extracts messages from a send
    queue, filled by the main thread, and returns the
    message to the client.
  • Requires the client to ask for each message.

12
.Net Remoting
  • The End
Write a Comment
User Comments (0)
About PowerShow.com