Пример #1
0
        /// <summary>
        /// Starts a new SINFONI server. This server provides its configuration document under the address that is
        /// provided in the constructor. When starting the server, the IDL given under the specified URL is parsed.
        /// Applications that access the server on its listening port will receive the config document that contains
        /// the implemented services as well as the IDL that is used by the server
        /// </summary>
        /// <param name="host">Host URL under which the server will be accessible</param>
        /// <param name="port">Specific port on which server is listening for incoming connections</param>
        /// <param name="path">Sub-Path on the server where the listener is running</param>
        /// <param name="idlURI">URI from where the IDL can be accessed</param>
        public SINFONIServer(string host, int port, string path, string idlURI)
        {
            ConfigHost = host;
            ConfigPort = port;
            ConfigPath = path;

            WebClient webClient = new WebClient();
            IdlContent = webClient.DownloadString(idlURI);

            IDLParser.Instance.ParseIDL(IdlContent);
            ServerConfigDocument = new Config();
            ServerConfigDocument.info = "TODO";
            ServerConfigDocument.idlURL = idlURI;
            ServerConfigDocument.servers = new List<ServiceDescription>();

            ConfigURI = "http://" + host + ":" + port + path;
            if(!idlURI.Contains("http://"))
            {

                ServerConfigDocument.idlURL = ConfigURI + idlURI + "/";
                IdlPath = path + idlURI + "/";
            }
            startHttpListener();
        }
Пример #2
0
        private ServiceDescription SelectServer(string fragment, Config config)
        {
            if (config.servers == null)
                throw new Error(ErrorCode.INIT_ERROR, "Configuration file contains no servers.");

            int serverNum = -1;
            if (!Int32.TryParse(fragment, out serverNum) || serverNum < 0 || serverNum >= config.servers.Count ||
                !IsServerProtocolSupported(config.servers[serverNum])) {
                serverNum = config.servers.FindIndex(s => IsServerProtocolSupported(s));
            }

            if (serverNum == -1)
                throw new Error(ErrorCode.INIT_ERROR, "Found no server with compatible protocol.");

            return config.servers[serverNum];
        }
Пример #3
0
        /// <summary>
        /// Creates a server specified in the config file retrieved from <paramref name="configURI"/>. Fragment part of
        /// the <paramref name="configURI"/> may be used to select the server by its index, e.g.
        /// <c>"http://www.example.org/config.json#3"</c>. If no fragment is provided, or index is invalid, first server
        /// with supported protocol is chosen. For each connected client <paramref name="onNewClient"/> is called with
        /// constructed Connection object.
        /// </summary>
        /// <remarks>
        /// Note that <paramref name="onNewClient"/> may be executed on a different thread than the one you are calling
        /// from, depending on the implementation of the protocol specified in the config file.
        /// </remarks>
        public ServiceDescription StartServer(string uri, int port, string transportName, string protocolName,
            Config ServerConfig, Action<Connection> onNewClient)
        {
            IProtocol protocol = protocolRegistry.GetProtocol(protocolName);
            ITransportConnectionFactory transportConnectionFactory = TransportRegistry.Instance
                .GetTransport(transportName)
                .TransportConnectionFactory;
            ITransportListener transportListener = transportConnectionFactory.StartConnectionListener(uri, port);
            transportListener.NewClientConnected += (object sender, NewConnectionEventArgs e) =>
            {
                Connection newConnection = new Connection(e.Connection, protocol);
                newConnection.LoadIDL(ServerConfig);
                onNewClient(newConnection);
            };

            var server = new ServiceDescription();
            server.protocol = new ProtocolConfig
            {
                name = protocolName
            };
            server.transport = new TransportConfig
            {
                name = transportName,
                url = transportName + "://" + uri  + ":" +port
            };
            server.implementedServices = "*";
            return server;
        }