private bool IsServerProtocolSupported(ServiceDescription server) { if (server.protocol == null) return false; string protocolName = server.protocol.name; if (protocolName == null) return false; return protocolRegistry.IsRegistered(protocolName.ToString()); }
/// <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; }