Example #1
0
        public static void Main()
        {
            const string portName       = "localhost:9090";
            IpcChannel   channel        = new IpcChannel(portName);
            const bool   ensureSecurity = false;

            ChannelServices.RegisterChannel(channel, ensureSecurity);

            Type         tAccount   = typeof(BankAccount);
            const string accountUri = "Account.rem";

            RemotingConfiguration.RegisterWellKnownServiceType(
                tAccount, accountUri, WellKnownObjectMode.Singleton);

            // Show the URIs associated with the channel.
            ChannelDataStore channelData = (ChannelDataStore)channel.ChannelData;

            foreach (string uri in channelData.ChannelUris)
            {
                Console.WriteLine("The channel URI is {0}.", uri);
            }

            string[] urls = channel.GetUrlsForUri("Account.rem");
            if (urls != null && urls.Length > 0)
            {
                string objectUrl = urls[0];
                Console.WriteLine("The Account object URL is {0}.", objectUrl);
            }

            Console.ReadLine();
            Console.WriteLine("Server stop loop.");
        }
Example #2
0
    public static void Main(string[] args)
    {
        //<snippet41>
        // Create the server channel.
        System.Collections.IDictionary properties =
            new System.Collections.Hashtable();
        properties["name"]     = "ipc";
        properties["priority"] = "20";
        properties["portName"] = "localhost:9090";
        IpcChannel serverChannel = new IpcChannel(properties, null, null);

        //</snippet41>

        // Register the server channel.
        ChannelServices.RegisterChannel(serverChannel);

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

        // Show the URIs associated with the channel.
        ChannelDataStore channelData =
            (ChannelDataStore)serverChannel.ChannelData;

        foreach (string uri in channelData.ChannelUris)
        {
            Console.WriteLine("The channel URI is {0}.", uri);
        }
// Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
Example #3
0
        public static void Main(string[] args)
        {
            IDictionary props = new Hashtable();

            props["port"] = 0; // let the system choose a free port
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            TcpChannel chan = new TcpChannel(props, clientProvider, serverProvider); // instantiate the channel

            ChannelServices.RegisterChannel(chan, false);                            // register the channel

            ChannelDataStore data = (ChannelDataStore)chan.ChannelData;
            int port = new Uri(data.ChannelUris[0]).Port; // get the port


            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteClient), "RemoteClient",
                                                               WellKnownObjectMode.Singleton); // register my remote object for service

            ClientApp.Init("tcp://localhost:" + port + "/RemoteClient");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new LoginWindow());
        }
        /// <summary>
        /// Замена имени хоста или IP-адреса
        /// </summary>
        /// <param name="dataStore">Данные канала</param>
        /// <param name="serverHostNameOrIp">Имя или адрес хоста, переданное с клиента</param>
        private void ReplaceHostNameOrIp(ChannelDataStore dataStore, string serverHostNameOrIp)
        {
            for (int i = 0; i < dataStore.ChannelUris.Length; i++)
            {
                if (_eventLink != null)
                {
                    _eventLink.Post(EventSource, string.Format(
                                        "Исходный URI в данных канала связи: {0}", dataStore.ChannelUris[i]));
                }

                UriBuilder ub = new UriBuilder(dataStore.ChannelUris[i]);

                // сравниваем имя хоста в URI канала и то же, переданное с клиента
                if (string.Compare(ub.Host, serverHostNameOrIp, true) != 0)
                {
                    // меняем на значение, переданное с клиента
                    ub.Host = serverHostNameOrIp;
                    dataStore.ChannelUris[i] = ub.ToString();

                    if (_eventLink != null)
                    {
                        _eventLink.Post(EventSource, string.Format(
                                            "Хост изменен. Новый URI: {0}", dataStore.ChannelUris[i]));
                    }
                }
            }
        }
Example #5
0
 private void WFService_Load(object sender, EventArgs e)
 {
     RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
     ;
     lstBxMessage.Items.Add("下列服务开启中......");
     IChannel[] channels = ChannelServices.RegisteredChannels;
     foreach (var channel in channels)
     {
         if (channel is TcpChannel)
         {
             TcpChannel       tcpchannel = (TcpChannel)channel;
             ChannelDataStore datastore  = (ChannelDataStore)tcpchannel.ChannelData;
             foreach (var uri in datastore.ChannelUris)
             {
                 lstBxMessage.Items.Add(uri);
             }
         }
         else
         {
             HttpChannel      httpchannel = (HttpChannel)channel;
             ChannelDataStore datastore   = (ChannelDataStore)httpchannel.ChannelData;
             foreach (var uri in datastore.ChannelUris)
             {
                 lstBxMessage.Items.Add(uri);
             }
         }
     }
 }
Example #6
0
    public static void Main()
    {
// <snippet31>
        // Set up a server channel.
        TcpServerChannel serverChannel = new TcpServerChannel(9090);

        ChannelServices.RegisterChannel(serverChannel);
// </snippet31>

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(Remotable), "Remotable.rem", WellKnownObjectMode.Singleton
            );

// <snippet32>
        // Show the name and priority of the channel.
        Console.WriteLine("Channel Name: {0}", serverChannel.ChannelName);
        Console.WriteLine("Channel Priority: {0}", serverChannel.ChannelPriority);
// </snippet32>

// <snippet33>
        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore)serverChannel.ChannelData;

        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine(uri);
        }
// </snippet33>

        // Wait for method calls.
        Console.WriteLine("Listening...");
        Console.ReadLine();
    }
 private void SetupChannel()
 {
     this._channelData = new ChannelDataStore(null);
     if (this._port > 0)
     {
         string channelUri = this.GetChannelUri();
         this._channelData.ChannelUris = new string[] { channelUri };
         this._wantsToListen           = false;
     }
     if (this._sinkProvider == null)
     {
         this._sinkProvider = this.CreateDefaultServerProviderChain();
     }
     CoreChannel.CollectChannelDataFromServerSinkProviders(this._channelData, this._sinkProvider);
     this._sinkChain          = ChannelServices.CreateServerChannelSinkChain(this._sinkProvider, this);
     this._transportSink      = new HttpServerTransportSink(this._sinkChain);
     base.SinksWithProperties = this._sinkChain;
     if (this._port >= 0)
     {
         this._tcpListener = new ExclusiveTcpListener(this._bindToAddr, this._port);
         ThreadStart start = new ThreadStart(this.Listen);
         this._listenerThread = new Thread(start);
         this._listenerThread.IsBackground = true;
         this.StartListening(null);
     }
 }
        internal void InitProviders(IServerChannelSinkProvider serverProviderChain)
        {
            _listener = null;
            _event    = new AutoResetEvent(false);

            _data                = new ChannelDataStore(null);
            _data.ChannelUris    = new String[1];
            _data.ChannelUris[0] = ChannelScheme + "://" + m_pipeName;

            _serverSinkProvider = serverProviderChain;

            // Create the default sink chain if one was not passed in
            if (_serverSinkProvider == null)
            {
                _serverSinkProvider = CreateDefaultServerProviderChain();
            }
            ;

            // Collect the rest of the channel data:
            IServerChannelSinkProvider provider = _serverSinkProvider;

            while (provider != null)
            {
                provider.GetChannelData(_data);
                provider = provider.Next;
            }

            IServerChannelSink next = ChannelServices.CreateServerChannelSinkChain(_serverSinkProvider, this);

            _transportSink = new PipeServerTransportSink(next);

            StartListening(null);
        }
        static void Main()
        {
            IDictionary props = new Hashtable();

            props["port"] = 0;  // let the system choose a free port
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            TcpChannel chan = new TcpChannel(props, clientProvider, serverProvider);  // instantiate the channel

            ChannelServices.RegisterChannel(chan, false);                             // register the channel

            ChannelDataStore data = (ChannelDataStore)chan.ChannelData;
            int port = new Uri(data.ChannelUris[0]).Port;                                                                            // get the port

            RemotingConfiguration.Configure("Client.exe.config", false);                                                             // register the server objects
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientNotify), "ClientNotify", WellKnownObjectMode.Singleton); // register my remote object for service

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormLogin(port)
            {
                FormBorderStyle = FormBorderStyle.FixedSingle
            });
        }
Example #10
0
        static void Main(string[] args)
        {
            // 创建一个IPC信道
            IpcChannel serverChannel = new IpcChannel("TestChannel");

            // 注册这个IPC信道.
            ChannelServices.RegisterChannel(serverChannel, false);

            // 打印这个信道的名称.
            Console.WriteLine("The name of the channel is {0}.", serverChannel.ChannelName);

            // 打印这个信道的优先级.
            Console.WriteLine("The priority of the channel is {0}.", serverChannel.ChannelPriority);

            // 打印这个信道的URI数组.
            ChannelDataStore channelData = (ChannelDataStore)serverChannel.ChannelData;

            foreach (string uri in channelData.ChannelUris)
            {
                Console.WriteLine("The channel URI is {0}.", uri);
            }

            // 向信道暴露一个远程对象.
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingObject), "RemoteObject.rem", WellKnownObjectMode.Singleton);

            Console.WriteLine("Press ENTER to exit the server.");
            Console.ReadLine();
        }
Example #11
0
        static void Main(string[] args)
        {
            TcpChannel channel = new TcpChannel(8086);

            ChannelServices.RegisterChannel(channel, false);
            ChannelDataStore data = (ChannelDataStore)channel.ChannelData;

            foreach (string uri in data.ChannelUris)
            {
                Console.WriteLine("The channel URI is {0}.", uri);
            }
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Server), "SuperChat", WellKnownObjectMode.Singleton);
            string[] urls = channel.GetUrlsForUri("SuperChat");
            if (urls.Length > 0)
            {
                string objectUrl = urls[0];
                string objectUri;
                string channelUri = channel.Parse(objectUrl, out objectUri);
                Console.WriteLine("The object URL is {0}.", objectUrl);
                Console.WriteLine("The object URI is {0}.", objectUri);
                Console.WriteLine("The channel URI is {0}.", channelUri);
            }
            System.Console.WriteLine("<enter> to leave...");
            System.Console.ReadLine();
        }
Example #12
0
        static void ShowChannelProperties(IChannelReceiver channel)
        {
            Console.WriteLine("Name:  {0}", channel.ChannelName);
            Console.WriteLine("Priority: {0}", channel.ChannelPriority);
            if (channel is TcpChannel)
            {
                TcpChannel tcpChannel = channel as TcpChannel;
                Console.WriteLine("is secured: {0}", tcpChannel.IsSecured);
            }

            if (channel is HttpServerChannel)
            {
                HttpServerChannel httpChannel = channel as HttpServerChannel;
                Console.WriteLine("Scheme: {0}", httpChannel.ChannelScheme);
            }

            ChannelDataStore data = (ChannelDataStore)channel.ChannelData;

            if (data != null)
            {
                foreach (string uri in data.ChannelUris)
                {
                    Console.WriteLine("URI: " + uri);
                }
            }
            Console.WriteLine();
        }
Example #13
0
        public static bool Init()
        {
            try {
                txId = -1;
                // Port 0 -> To request that an available port be dynamically assigned
                channel = new TcpChannel(0);
                ChannelServices.RegisterChannel(channel, false);
                try {
                    masterServer = (IMasterServer)Activator.GetObject(typeof(IMasterServer), urlMaster);
                } catch (RemotingException re) {
                    Console.WriteLine("[Init]:\n" + re);
                    return(false);
                    //throw new TxException(txId, "TxCommit transaction with id " + txId + "failed. canCommit voting failed.");
                }
                ChannelDataStore data = (ChannelDataStore)channel.ChannelData;
                clientUrl = (String)data.ChannelUris[0];
                //try {
                masterServer.registerClient(clientUrl);
                //} catch (RemotingException re) {

                //}
                return(true);
            } catch (Exception e) {
                Console.WriteLine("Init Exception:" + e);
                return(false);
            }
        }
        private void SetupChannel()
        {
            if (this.authSet && !this._secure)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Tcp_AuthenticationConfigServer"));
            }
            this._channelData = new ChannelDataStore(null);
            if (this._port > 0)
            {
                this._channelData.ChannelUris = new string[] { this.GetChannelUri() };
            }
            if (this._sinkProvider == null)
            {
                this._sinkProvider = this.CreateDefaultServerProviderChain();
            }
            CoreChannel.CollectChannelDataFromServerSinkProviders(this._channelData, this._sinkProvider);
            IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(this._sinkProvider, this);

            this._transportSink        = new TcpServerTransportSink(nextSink, this._impersonate);
            this._acceptSocketCallback = new AsyncCallback(this.AcceptSocketCallbackHelper);
            if (this._port >= 0)
            {
                this._tcpListener = new ExclusiveTcpListener(this._bindToAddr, this._port);
                this.StartListening(null);
            }
        }
Example #15
0
        void Init(IServerChannelSinkProvider provider)
        {
            if (provider == null)
            {
                provider = new SimpleServerFormatterSinkProvider();
            }

            IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain(provider, this);

            host = Dns.GetHostByName(Dns.GetHostName()).HostName;

            string [] uris = null;

            if (port != 0)
            {
                uris     = new String [1];
                uris [0] = GetChannelUri();
            }

            channel_data = new ChannelDataStore(uris);;

            sink = new SimpleServerTransportSink(next_sink);

            listener = new TcpListener(port);
            StartListening(null);
        }
Example #16
0
        static void Main()
        {
            IDictionary props = new Hashtable();

            props["port"] = 0;  // let the system choose a free port
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            TcpChannel chan = new TcpChannel(props, clientProvider, serverProvider);    // instantiate the channel

            ChannelServices.RegisterChannel(chan, false);                               // register the channel


            ChannelDataStore data = (ChannelDataStore)chan.ChannelData;
            int port = new Uri(data.ChannelUris[0]).Port;                               // get the port


            RemotingConfiguration.Configure("ChatClient.exe.config", false);                                                  // register the server objects
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemMessage), "Message", WellKnownObjectMode.Singleton); // register my remote object for service


            Login login = new Login(port.ToString());

            Application.EnableVisualStyles();
            Application.Run(login);
        }
Example #17
0
        void Init(IServerChannelSinkProvider serverSinkProvider)
        {
            if (serverSinkProvider == null)
            {
                serverSinkProvider = new UnixBinaryServerFormatterSinkProvider();
            }

            // Gets channel data from the chain of channel providers

            channel_data = new ChannelDataStore(null);
            IServerChannelSinkProvider provider = serverSinkProvider;

            while (provider != null)
            {
                provider.GetChannelData(channel_data);
                provider = provider.Next;
            }

            // Creates the sink chain that will process all incoming messages

            IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain(serverSinkProvider, this);

            sink = new UnixServerTransportSink(next_sink);

            StartListening(null);
        }
Example #18
0
        void Init(IServerChannelSinkProvider serverSinkProvider)
        {
            if (serverSinkProvider == null)
            {
                serverSinkProvider = new BinaryServerFormatterSinkProvider();
            }

            if (host == null)
            {
                if (useIpAddress)
                {
                    if (!bindAddress.Equals(IPAddress.Any))
                    {
                        host = bindAddress.ToString();
                    }
                    else
                    {
                        IPHostEntry he = Dns.Resolve(Dns.GetHostName());
                        if (he.AddressList.Length == 0)
                        {
                            throw new RemotingException("IP address could not be determined for this host");
                        }
                        AddressFamily addressFamily = (Socket.SupportsIPv4) ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6;
                        IPAddress     addr          = GetMachineAddress(he, addressFamily);
                        if (addr != null)
                        {
                            host = addr.ToString();
                        }
                        else
                        {
                            host = he.AddressList [0].ToString();
                        }
                    }
                }
                else
                {
                    host = Dns.GetHostByName(Dns.GetHostName()).HostName;
                }
            }

            // Gets channel data from the chain of channel providers

            channel_data = new ChannelDataStore(null);
            IServerChannelSinkProvider provider = serverSinkProvider;

            while (provider != null)
            {
                provider.GetChannelData(channel_data);
                provider = provider.Next;
            }

            // Creates the sink chain that will process all incoming messages

            IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain(serverSinkProvider, this);

            sink = new TcpServerTransportSink(next_sink);

            StartListening(null);
        }
Example #19
0
        public virtual void WriteProxy(object o, Type ot)
        {
            if (!RemotingServices.IsTransparentProxy(o))
            {
                Console.WriteLine("o {0} ot {1} is not transparent proxy!", o, ot);
                throw new InvalidOperationException("object which is not a transparent proxy passed to WriteProxy, type " + ot);
            }

            ObjRef or = RemotingServices.GetObjRefForProxy((System.MarshalByRefObject)o);

            Ice.Identity proxy_ident = new Ice.Identity(or.URI.StartsWith("/") ? or.URI.Substring(1) : or.URI);
            Ice.Endpoint proxy_ep    = null;

            foreach (object cdo in or.ChannelInfo.ChannelData)
            {
                ChannelDataStore cd = cdo as ChannelDataStore;
                if (cd == null)
                {
                    continue;
                }
                foreach (string ch_uri in cd.ChannelUris)
                {
                    string host;
                    int    port;
                    string uri;

                    if (IceChannelUtils.ParseIceURL(ch_uri, out host, out port, out uri))
                    {
                        proxy_ep          = new Ice.TcpEndpoint(host, port);
                        proxy_ep.Incoming = true;
                        break;
                    }
                }
            }

            if (proxy_ep == null)
            {
                throw new InvalidOperationException("Couldn't find valid Ice endpoint/channel for " + o);
            }

            Ice.ProxyData pd = new Ice.ProxyData();
            pd.id     = proxy_ident;
            pd.facet  = new string[0];
            pd.mode   = ProxyMode.Twoway; // FIXME -- do I need to send multiple proxy things here?
            pd.secure = false;

            WriteStruct(pd);
            WriteSize(1);       // one endpoint follows

            // tcp endpoint encapsulation
            WriteObject((short)1); // it's a TCP endpoint
            BeginEncapsulation();
            Ice.TcpEndpoint te = proxy_ep as Ice.TcpEndpoint;
            Write(te.host);
            WriteObject(te.port);
            WriteObject(te.timeout);
            WriteObject(te.compress);
            EndEncapsulation();
        }
        /**
         * Creates a new One2One channel with the filtering options set for this factory and the specified
         * data buffer.
         *
         * @param buffer the buffer implementation to use.
         * @return the created filtered channel.
         */
        public One2OneChannel createOne2One(ChannelDataStore buffer)
        {
            FilteredOne2OneChannelImpl toReturn =
                new FilteredOne2OneChannelImpl(factory.createOne2One(buffer));

            installFilters(toReturn.inFilter(), toReturn.outFilter());
            return(toReturn);
        }
        /**
         * Creates a new Any2Any channel with the filtering options set for this factory and the specified
         * data buffer.
         *
         * @param buffer the buffer implementation to use.
         * @return the created filtered channel.
         */
        public Any2AnyChannel createAny2Any(ChannelDataStore buffer)
        {
            FilteredAny2AnyChannelImpl toReturn =
                new FilteredAny2AnyChannelImpl(factory.createAny2Any(buffer));

            installFilters(toReturn.inFilter(), toReturn.outFilter());
            return(toReturn);
        }
Example #22
0
        public void Bug81653()
        {
            IpcClientChannel c  = new IpcClientChannel();
            ChannelDataStore cd = new ChannelDataStore(new string[] { "foo" });
            string           objectUri;

            c.CreateMessageSink(null, cd, out objectUri);
        }
Example #23
0
        /// <summary>
        /// Creates a server channel.
        /// </summary>
        /// <param name="properties">The channel properties.</param>
        /// <param name="provider">The sink provider.</param>
        public IpcServerChannel(IDictionary properties, IServerChannelSinkProvider provider)
        {
            bool impersonate = false;

            if (properties != null)
            {
                foreach (DictionaryEntry e in properties)
                {
                    switch ((string)e.Key)
                    {
                    case "name":
                        channelName = (string)e.Value;
                        break;

                    case "priority":
                        channelPriority = Convert.ToInt32(e.Value);
                        break;

                    case "portName":
                        portName = (string)e.Value;
                        if (!IpcChannelHelper.IsValidPipeName(portName))
                        {
                            throw new ArgumentException("Invalid pipe name.", "portName");
                        }
                        break;

                    case "impersonate":
                        impersonate = Boolean.Parse((string)e.Value);
                        break;
                    }
                }
            }

            if (portName == null)
            {
                portName = Guid.NewGuid().ToString("N");
            }

            serverProvider = provider;

            if (serverProvider == null)
            {
                serverProvider = new BinaryServerFormatterSinkProvider();
            }

            dataStore = new ChannelDataStore(
                new string[] { IpcChannelHelper.SchemeStart + portName }
                );
            PopulateChannelData(dataStore, serverProvider);

            sink = new IpcServerChannelSink(
                ChannelServices.CreateServerChannelSinkChain(serverProvider, this),
                portName,
                impersonate
                );

            StartListening(null);
        }
Example #24
0
        static void Main(string[] args)
        {
            Console.WriteLine("╔════════════════════════════════════════════════════╗");
            Console.WriteLine("║                    Pacman Server                   ║");
            Console.WriteLine("║             DAD 2017-2018, IST - Group 4           ║");
            Console.WriteLine("╚════════════════════════════════════════════════════╝");

            Console.WriteLine("{0} arguments.", args.Length);
            foreach (string arg in args)
            {
                Console.WriteLine("arg: {0}", arg);
            }

            try
            {
                endpoint   = new Uri(args.Length > 0 ? args[0] : "tcp://localhost:8086/OGPGameServer");
                msec       = (args.Length > 1) ? Int32.Parse(args[1]) : 20;
                numPlayers = (args.Length > 2) ? Int32.Parse(args[2]) : 2;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Expected arguments: <url> <msec> <numPlayers>");
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                Environment.Exit(-1);
            }

            Console.WriteLine("URI:\t{0}", endpoint);
            Console.WriteLine("MSEC:\t{0}", msec);
            Console.WriteLine("Pla#:\t{0}", numPlayers);
            Console.WriteLine("Path:\t{0}", endpoint.AbsolutePath);
            Console.WriteLine("Requested Host:\t{0}", endpoint.Host);

            TcpChannel channel = new TcpChannel(endpoint.Port);

            ChannelServices.RegisterChannel(channel, false);

            string objName = endpoint.AbsolutePath.Replace("/", "");

            Console.WriteLine("objName:\t{0}", objName);
            Console.WriteLine();
            // get channel host
            ChannelDataStore data = (ChannelDataStore)channel.ChannelData;

            foreach (string uriStr in data.ChannelUris)
            {
                Console.WriteLine("Server at:\t{0}/{1}", uriStr, objName);
            }
            Console.WriteLine();

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(ServerGameService),
                objName,
                WellKnownObjectMode.Singleton);

            Console.ReadKey();
        }
 /**
  * Constructs and returns an array of <code>One2OneChannel</code>
  * objects with a given buffering behaviour.
  *
  * @param	n	the size of the array of channels.
  * @param buffer the buffer implementation to use.
  * @return the array of channels.
  *
  * @see jcsp.lang.ChannelArrayFactory#createOne2One(int)
  */
 public One2OneChannel[] createOne2One(ChannelDataStore buffer, int n)
 {
     One2OneChannel[] toReturn = new One2OneChannel[n];
     for (int i = 0; i < n; i++)
     {
         toReturn[i] = createOne2One(buffer);
     }
     return(toReturn);
 }
 /**
  * Constructs and returns an array of <code>Any2AnyChannel</code>
  * objects with a given buffering behaviour.
  *
  * @param	n	the size of the array of channels.
  * @param buffer the buffer implementation to use.
  * @return the array of channels.
  *
  * @see jcsp.lang.ChannelArrayFactory#createAny2Any(int)
  */
 public Any2AnyChannel[] createAny2Any(ChannelDataStore buffer, int n)
 {
     Any2AnyChannel[] toReturn = new Any2AnyChannel[n];
     for (int i = 0; i < n; i++)
     {
         toReturn[i] = createAny2Any(buffer);
     }
     return(toReturn);
 }
Example #27
0
 /**
  * Constructs a new BufferedOne2OneChannel with the specified ChannelDataStore.
  *
  * @param data the ChannelDataStore used to store the data for the channel
  */
 public BufferedOne2OneChannel(ChannelDataStore data)
 {
     if (data == null)
     {
         throw new ArgumentException
                   ("Null ChannelDataStore given to channel constructor ...\n");
     }
     this.data = (ChannelDataStore)data.Clone();
 }
Example #28
0
 void PopulateChannelData(ChannelDataStore channelData,
                          IServerChannelSinkProvider provider)
 {
     while (provider != null)
     {
         provider.GetChannelData(channelData);
         provider = provider.Next;
     }
 }
Example #29
0
    public static void Main(string[] args)
    {
        //<snippet2>
        // Create the server channel.
        TcpChannel serverChannel = new TcpChannel(9090);

        //</snippet2>

        // Register the server channel.
        ChannelServices.RegisterChannel(serverChannel);

        //<snippet3>
        // Show the name of the channel.
        Console.WriteLine("The name of the channel is {0}.",
                          serverChannel.ChannelName);
        //</snippet3>

        //<snippet4>
        // Show the priority of the channel.
        Console.WriteLine("The priority of the channel is {0}.",
                          serverChannel.ChannelPriority);
        //</snippet4>

        //<snippet5>
        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore)serverChannel.ChannelData;

        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine("The channel URI is {0}.", uri);
        }
        //</snippet5>

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

        //<snippet6>
        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri = serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
        }
        //</snippet6>

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
    }
Example #30
0
        public static Any2AnyChannel[] any2anyArray(int size, ChannelDataStore data, int immunity)
        {
            Any2AnyChannel[] r = new Any2AnyChannel[size];
            for (int i = 0; i < size; i++)
            {
                r[i] = any2any(data, immunity);
            }

            return(r);
        }
Example #31
0
		void Init (IServerChannelSinkProvider provider) {
			if (provider == null) {
				provider = new CORBAServerFormatterSinkProvider ();
			}
			
			IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain (provider, this);

			host = Dns.GetHostByName(Dns.GetHostName()).HostName;
			
			string [] uris = null;
			
			if (port != 0) {
				uris = new String [1];
				uris [0] = GetChannelUri ();
			}
			
			channel_data = new ChannelDataStore (uris);;

			sink = new CORBAServerTransportSink (next_sink);
			
			listener = new TcpListener (port);
			StartListening (null);
		}
Example #32
0
		void BuildSink (IServerChannelSinkProvider sinkProvider)
		{
			//resolve names (modified from TcpChannel)
			if (machineName == null) {
				if (useIPAddress) {
					if (!bindAddress.Equals (IPAddress.Any)) {
						machineName = bindAddress.ToString ();
					} else {
						IPHostEntry hostEntry = Dns.Resolve (Dns.GetHostName ());
						if (hostEntry.AddressList.Length == 0)
							throw new RemotingException ("IP address could not be determined for this host");
						// We DON'T want to take the resolved address from the hostEntry, since the socket
						// should still bind to IPAddress.Any, so that we get the loopback too
						machineName = hostEntry.AddressList[0].ToString ();
					}
				} else {
					IPHostEntry hostEntry = Dns.GetHostByName (Dns.GetHostName ());
					bindAddress = hostEntry.AddressList[0];
					machineName = hostEntry.HostName;
				}
			}

			if (sinkProvider == null) {
				//build a default chain that can handle wsdl, soap, binary
				sinkProvider = new SdlChannelSinkProvider (); //for wsdl
				sinkProvider.Next = new SoapServerFormatterSinkProvider ();
				sinkProvider.Next.Next = new BinaryServerFormatterSinkProvider ();
			}
			
			//MS compat: channelData is null when port < 0
			if (port >= 0) {
				channelData = new ChannelDataStore (null);
				IServerChannelSinkProvider provider = sinkProvider;
				while (provider != null) {
					provider.GetChannelData (channelData);
					provider = provider.Next;
				}
			}
			
			//create the sink chain and add an HTTP sink
			IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain (sinkProvider, this);
			sink = new HttpServerTransportSink (nextSink);

			// BaseChannelWithProperties wants this to be set with the chain
			base.SinksWithProperties = nextSink;

			StartListening (null);
		}
Example #33
0
        private void Init(IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
        {
            pool = new TcpConnectionPool();
            if(clientSinkProvider == null)
            {
                this.clientSinkProvider = new BinaryClientFormatterSinkProvider();
                this.clientSinkProvider.Next = new TcpClientSinkProvider(pool, timeout);
            }
            else
            {
                this.clientSinkProvider = clientSinkProvider;
                IClientChannelSinkProvider provider = clientSinkProvider;
                while(provider.Next != null)
                    provider = provider.Next;
                provider.Next = new TcpClientSinkProvider(pool, timeout);
            }

            if(serverSinkProvider == null)
                serverSinkProvider = new BinaryServerFormatterSinkProvider();

            try
            {
                if(host != null)
                {
                    if(useIpAddress)
                        host = Dns.GetHostName();
                }
                else if(bindTo != IPAddress.Any)
                    host = bindTo.ToString();
                else
                {
                    IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
                    if(addresses.Length == 0)
                        throw new RemotingException("TCP error: IP address could not be determined for this host!");
                    host = addresses[0].ToString();
                }
            }
            catch(SocketException e)
            {
                throw new RemotingException("TCP error: DNS error!", e);
            }

            channelData = new ChannelDataStore(new string[] { "tcp://" + TcpConnection.ThisMachineID });
            for(IServerChannelSinkProvider provider = serverSinkProvider; provider != null; provider = provider.Next)
                provider.GetChannelData(channelData);

            IServerChannelSink chain = ChannelServices.CreateServerChannelSinkChain(serverSinkProvider, this);
            serverSink = new TcpServerSink(chain);

            StartListening(null);
        }
Example #34
0
		public void AddHookChannelUri (string channelUri)
		{
			string [] newUris = new string[1] { channelUri };
			if (channelData == null)
				channelData = new ChannelDataStore (newUris);
			else
				channelData.ChannelUris = newUris;
			wantsToListen = false;
		}
Example #35
0
        private void Init(IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
        {
            if(clientSinkProvider == null)
            {
                this.clientSinkProvider = new BinaryClientFormatterSinkProvider();
                this.clientSinkProvider.Next = new TcpClientSinkProvider(pool, timeout);
            }

            else
            {
                this.clientSinkProvider = clientSinkProvider;
                IClientChannelSinkProvider provider = clientSinkProvider;
                while(provider.Next != null)
                    provider = provider.Next;
                provider.Next = new TcpClientSinkProvider(pool, timeout);
            }

            if(serverSinkProvider == null)
                serverSinkProvider = new BinaryServerFormatterSinkProvider();

            channelData = new ChannelDataStore(new string[] { "tcp://" + TcpConnection.ThisMachineID });
            for(IServerChannelSinkProvider provider = serverSinkProvider; provider != null; provider = provider.Next)
                provider.GetChannelData(channelData);

            IServerChannelSink chain = ChannelServices.CreateServerChannelSinkChain(serverSinkProvider, this);
            serverSink = new TcpServerSink(chain);

            StartListening(null);
        }