I have created SignalR functionalities in a console application. I am able to invoke a server function from client, but when I am trying to send a message from the server to the client, the sever console is closing.
Below is my code:
Sever Code
Below code used in Hub inherited class
[HubName("TestHub")]
public class TestHub: Hub
{
public void NotifyAllClients()
{
Clients.Caller.notify();
}
}
Startup Class
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.Owin.Cors;
using Microsoft.AspNet.SignalR;
[assembly: OwinStartup(typeof(ConsoleApp1.Startup))]
namespace ConsoleApp1
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
Main Class
static void Main(string[] args)
{
string url = @"http://localhost:8080/";
using (WebApp.Start<Startup>(url))
{
Console.WriteLine(string.Format("Server running at {0}", url));
Console.ReadLine();
}
}
Client Code
IHubProxy _hub;
string url = @"http://localhost:8080/";
var connection = new HubConnection(url);
_hub = connection.CreateHubProxy("TestHub");
connection.Start();
_hub.On("notify", () => Console.WriteLine("Notified!"));