Exemple #1
0
        public static void RegisterAndStart(string serviceName, IToyOrbService serviceImpl, string nsHost = DefaultHostname, int nsPort = DefaultPort)
        {
            ServerSideProxy serviceProxy = BindAvailablePort(serviceName, serviceImpl);

            var request   = new ServiceRegistrationMessage(serviceName, serviceImpl.ServiceType, serviceProxy.Port);
            var requestor = new Requestor <ServiceRegistrationMessage, NameResponseMessage>(nsHost, nsPort);
            NameResponseMessage response = requestor.MakeRequest(request);

            response.Check();

            serviceProxy.Start();
        }
Exemple #2
0
        private static ServerSideProxy BindAvailablePort(string serviceName, IToyOrbService serviceImpl)
        {
            var random = new Random();
            var ports  = Enumerable.Range(MinObjPort, MaxObjPort).OrderBy(p => random.NextDouble());

            foreach (int port in ports)
            {
                try
                {
                    var proxy = new ServerSideProxy(port, serviceName, serviceImpl);
                    proxy.Bind();
                    return(proxy);
                }
                catch (SocketException e)
                {
                    Console.WriteLine(e);
                }
            }

            throw new IOException("failed to find available port");
        }