简体   繁体   English

如何在同一个控制台应用程序中运行客户端和自托管服务器?

[英]How to run a client and self hosted server in the same console app?

I have a self hosted signalR app in .NET core and I want to run a socketIO client that connects with a completely different socketIO server but when I run the signalR server, the socketIO client is not able to receive commands from the external socketIO server.我在 .NET 核心中有一个自托管的 signalR 应用程序,我想运行一个与完全不同的 socketIO 服务器连接的 socketIO 客户端,但是当我运行 signalR 服务器时,套接字无法从外部 IO 服务器接收命令。 I have tried using threads to run the socketIO client buy no luck there.我曾尝试使用线程来运行 socketIO 客户端,但没有运气。 My guess is that when I run the SignalR server with "host.Run()" command mentioned in the code below, it blocks my socketIO client connection somehow.我的猜测是,当我使用下面代码中提到的“host.Run()”命令运行 SignalR 服务器时,它会以某种方式阻止我的 socketIO 客户端连接。 How can I run a SignalR server (self hosted) and a socketIO client on the same console app so that they don't block each other?如何在同一个控制台应用程序上运行 SignalR 服务器(自托管)和 socketIO 客户端,以免它们相互阻塞? PS I am using the 'SocketIOClient' nuget package for creating socketIO client. PS我正在使用'SocketIOClient' nuget package 来创建socketIO客户端。 My code looks somewhat like this:我的代码看起来有点像这样:

''' '''

        string serviceAddress = ConfigurationManager.AppSettings["SocketIOServerAddress"];

        // Get SignalR hub context
        var host = CreateHostBuilder(args).Build();
        var hubContext = host.Services.GetService(typeof(IHubContext<MyHub>));

        socketClient = new MySocketIOClient((IHubContext<MyHub>)hubContext, serviceAddress);

        await Task.Factory.StartNew(async () => {
            await socketClient.ConnectAsync();
            Console.ReadKey();
        });

        Console.WriteLine("Starting SignalR host...");

        //host.Run();
        await Task.Factory.StartNew(() => { host.Run(); });

''' '''

You could try running either one in a background service: https://blog.computedcloud.com/background-services-in-net-core-console-app/您可以尝试在后台服务中运行任何一个: https://blog.computedcloud.com/background-services-in-net-core-console-app/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有自托管的 SignalR 客户端服务器应用程序 - SignalR client server application with self hosted 在自托管的c#WCF控制台应用程序中使用web.config(设置MaxStringContentLength服务器端) - Using web.config in a Self-Hosted c# WCF console app (setting MaxStringContentLength server side) 从自托管的WEB API控制台应用程序返回jsonp - Return jsonp from self hosted WEB API Console app Azure Signalr + Azure函数+ wpf客户端-如何使用azure函数和自托管的Azure SignalR App创建wpf客户端应用程序 - Azure Signalr +Azure function + wpf client - how to have a wpf client application using azure funtion and self hosted Azure SignalR App 自托管 GRPC 服务器 - Self hosted GRPC server Self Hosted Asp Net Core Web 服务器,使用自签名证书进行客户端身份验证 - Self Hosted Asp Net Core Web server, client authentication with self-signed certificates 在自托管 OWIN Web API 中,如何在关机时运行代码? - In self-hosted OWIN Web API, how to run code at shutdown? 如何在发布服务器项目而不是客户端的 Azure DevOps 上为 Blazor WebAssembly 托管应用程序创建构建管道? - How to create a build pipeline for Blazor WebAssembly Hosted app on Azure DevOps that publishes the server project not the client? 自托管WCF服务器和SSL - Self - hosted WCF server and SSL 如何在同一台计算机上运行客户端和服务器UDP侦听器 - How to run client and server UDP listeners on the same machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM