本文整理汇总了C#中System.Net.Connection.LoadIDL方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.LoadIDL方法的具体用法?C# Connection.LoadIDL怎么用?C# Connection.LoadIDL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Connection
的用法示例。
在下文中一共展示了Connection.LoadIDL方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenConnection
/// <summary>
/// Opens a connection to a server specified in the config file retrived 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. Upon connection <paramref name="onConnected"/> is called with the
/// constructed Connection object.
/// </summary>
/// <param name="configURI">
/// URI where config is to be found. Data URIs starting with <c>"data:text/json;base64,"</c> are supported.
/// </param>
/// <param name="onConnected">Handler to be invoked when connection is established.</param>
public void OpenConnection(string configURI, Action<Connection> onConnected)
{
string fragment = "";
Config ServerConfiguration = RetrieveConfig(configURI, out fragment);
ServiceDescription server = SelectServer(fragment, ServerConfiguration);
string protocolName = server.protocol.name;
string transportName = server.transport.name;
string transportUrl = server.transport.url;
string host;
int port;
GetHostAndPortFromUrl(transportUrl, out host, out port);
ITransportConnectionFactory transportConnectionFactory = TransportRegistry.Instance
.GetTransport(transportName)
.TransportConnectionFactory;
IProtocol protocol = protocolRegistry.GetProtocol(protocolName);
ITransportConnection transportConnection = transportConnectionFactory.OpenConnection(host, port, this, onConnected);
transportConnection.Opened += (sender, e) =>
{
Connection establishedConnection = new Connection(transportConnection, protocol);
establishedConnection.LoadIDL(ServerConfiguration);
onConnected(establishedConnection);
};
}
示例2: StartServer
/// <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;
}