コード例 #1
0
        public static void Main()
        {
            try
            {
                TcpChannel myTcpChannel = new TcpChannel(8084);
                ChannelServices.RegisterChannel(myTcpChannel);
                HelloServer myHelloServer = (HelloServer)Activator.GetObject(typeof
                                                                             (RemotingSamples.HelloServer), "tcp://localhost:8080/SayHello");
                if (myHelloServer == null)
                {
                    System.Console.WriteLine("Could not locate server");
                }
                else
                {
// <Snippet4>
                    string[] myURLArray = ChannelServices.GetUrlsForObject(myHelloServer);
                    Console.WriteLine("Number of URLs for the specified Object: "
                                      + myURLArray.Length);
                    for (int iIndex = 0; iIndex < myURLArray.Length; iIndex++)
                    {
                        Console.WriteLine("URL: " + myURLArray[iIndex]);
                    }
// </Snippet4>
                    Console.WriteLine(myHelloServer.HelloMethod("Caveman"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught!!!");
                Console.WriteLine("The source of exception: " + e.Source);
                Console.WriteLine("The Message of exception: " + e.Message);
            }
        }
コード例 #2
0
ファイル: CDService.cs プロジェクト: sanchaz/PADITable
        public CDService(string username, string port)
        {
            mCDChannel = new TcpChannel(Int32.Parse(port));
            ChannelServices.RegisterChannel(mCDChannel, true);

            RemotingServices.Marshal(this, username, typeof(ICentralDir));
            string[] urls = ChannelServices.GetUrlsForObject(this);
            System.Console.WriteLine("Central Directory instantiated with URL " + urls[0]);

            mParticipantMngr = new ParticipantManager();
            mCdThread        = new CDThread();
        }
コード例 #3
0
        public Client(string username, string port, string cDirUrl)
        {
            //With 0 as port the remoting services will chose an available port automatically
            IDictionary prop = new Hashtable();

            prop["name"]   = "ClientChannel." + username;
            prop["port"]   = port;
            mClientChannel = new TcpChannel(prop, null, null);
            ChannelServices.RegisterChannel(mClientChannel, true);

            string clientName = username;

            RemotingServices.Marshal(this, clientName, typeof(IClient));

            String[] urls = ChannelServices.GetUrlsForObject(this);

            this.URL = urls[0];

            System.Console.WriteLine("Client instantiated with name " + clientName + " and URL " + urls[0]);

            try
            {
                CDIR_URL    = cDirUrl;
                mCentralDir = (ICentralDir)Activator.GetObject(typeof(IClient), CDIR_URL);

                if (mCentralDir == null)
                {
                    System.Console.WriteLine("Cannot get central directory object for " + CDIR_URL);
                    throw new RemoteException("Cannot get central directory object for " + CDIR_URL);
                }
            }
            catch (SocketException)
            {
                throw new RemoteException("Could not connect to central directory: central directory url " + CDIR_URL);
            }

            System.Console.WriteLine("Central Directory with URL " + CDIR_URL);

            isSleep          = false;
            mRegisterManager = new RegisterManager();
            mNodeRouter      = new NodeRouter();
            mClientThread    = new ClientThread();

            System.Console.WriteLine("Register Manager created");
            System.Console.WriteLine("Node Router created");
            System.Console.WriteLine("Client Thread created");

            mActiveTransaction = new TransactionContext();
            System.Console.Write("Transaction Context created with id: " + mActiveTransaction.TxID + " valuesOfKey: ");
            mActiveTransaction.printKeyValues();
            System.Console.WriteLine("state: " + mActiveTransaction.TransactionState);
        }
コード例 #4
0
        public Server(string username, string port, string cDirUrl)
        {
            IDictionary prop = new Hashtable();

            prop["name"]   = "ServerChannel." + username;
            prop["port"]   = port;
            mServerChannel = new TcpChannel(prop, null, null);
            ChannelServices.RegisterChannel(mServerChannel, true);

            string serverName = username;

            RemotingServices.Marshal(this, serverName, typeof(IServer));
            String[] urls = ChannelServices.GetUrlsForObject(this);
            this.URL = urls[0];
            System.Console.WriteLine("Server instantiated with name " + serverName + " " + urls[0]);

            try
            {
                CDIR_URL    = cDirUrl;
                mCentralDir = (ICentralDir)Activator.GetObject(typeof(IClient), CDIR_URL);

                if (mCentralDir == null)
                {
                    System.Console.WriteLine("Cannot get central directory object for " + CDIR_URL);
                    throw new RemoteException("Cannot get central directory object for " + CDIR_URL);
                }
            } catch (SocketException) {
                // throw new RemoteException("Could not connect to central directory: central directory url " + CDIR_URL);
                System.Console.WriteLine("Could not connect to central directory: central directory url " + CDIR_URL);
                Environment.Exit(0);
            }

            mKeyManager         = new KeyManager(K);
            mTransactionManager = new TransactionManager(this, mKeyManager, K);
            mNodeRouter         = new NodeRouter(mURL, mKeyManager, this);
            mServerThread       = new ServerThread(mNodeRouter, mKeyManager);
        }