[英]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.