//public async Task CallZomeFunction(JsonRpcHttpClient client) //{ // return await client.Invoke<string>("info/instances").Result; //} public async Task CallZomeFunction(string holoChainServerURI) { try { HttpListener httpListener = new HttpListener(); httpListener.Prefixes.Add("http://localhost:8888/"); httpListener.Start(); HttpListenerContext context = await httpListener.GetContextAsync(); if (context.Request.IsWebSocketRequest) { HttpListenerWebSocketContext webSocketContext = await context.AcceptWebSocketAsync(null); System.Net.WebSockets.WebSocket webSocket = webSocketContext.WebSocket; StreamJsonRpc.JsonRpc client = new StreamJsonRpc.JsonRpc(new WebSocketMessageHandler(webSocket)); client.StartListening(); string result = await client.InvokeAsync <string>("info/instances"); await client.Completion; //while (webSocket.State == WebSocketState.Open) //{ // await webSocket.SendAsync() //} } } catch (Exception ex) { } }
/// <nodoc/> public App(Stream clientStream, Stream serverStream, string pathToLogFile) { Contract.Requires(clientStream != null); Contract.Requires(serverStream != null); Contract.Requires(!string.IsNullOrEmpty(pathToLogFile)); ContentHashingUtilities.SetDefaultHashType(); // Note that we cannot start listening (i.e. use Attach) until // we have finished constructing the app. // Otherwise we can receive an incoming message // before we finish initialization. var jsonRpcChannel = new JsonRpcWithException(clientStream, serverStream, this); m_mainRpcChannel = jsonRpcChannel; m_mainRpcChannel.AddLocalRpcTarget(this, new JsonRpcTargetOptions { AllowNonPublicInvocation = true }); // We need to create the project management provider before we start listening on the // RPC channel as you cannot attach them after it has started listening. m_projectManagementProvider = new ProjectManagementProvider(GetAppStateDelegate(), m_mainRpcChannel); m_tracer = new Tracer(m_mainRpcChannel, pathToLogFile, EventLevel.Verbose, EventLevel.Informational); m_progressReporter = new ProgressReporter(m_mainRpcChannel, testContext: null); Logger.LanguageServerStarted(LoggingContext); Logger.LanguageServerLogFileLocation(LoggingContext, pathToLogFile); jsonRpcChannel.SetLoggingContext(Logger, LoggingContext); // Change minimal number of threads for performance reasons. // 5 is a reasonable number that should prevent thread pool exhaustion and will not spawn too many threads. ThreadPoolHelper.ConfigureWorkerThreadPools(Environment.ProcessorCount, 5); // This must be last after initialization m_mainRpcChannel.StartListening(); SubscribeToUnhandledErrors(); }
/// <summary> /// Initializes a new instance of the <see cref="JsonRpc"/> class and immediately starts listening. /// </summary> /// <param name="sendingStream">The stream used to transmit messages. May be null.</param> /// <param name="receivingStream">The stream used to receive messages. May be null.</param> /// <param name="target">An optional target object to invoke when incoming RPC requests arrive.</param> /// <returns>The initialized and listening <see cref="JsonRpc"/> object.</returns> public static JsonRpc Attach(Stream sendingStream, Stream receivingStream, object target = null) { if (sendingStream == null && receivingStream == null) { throw new ArgumentException(Resources.BothReadableWritableAreNull); } var rpc = new JsonRpc(sendingStream, receivingStream, target); try { if (receivingStream != null) { rpc.StartListening(); } return(rpc); } catch { rpc.Dispose(); throw; } }