I am trying to call a console app method from SignalR HUB context which is not working-
var hubContext = GlobalHost.ConnectionManager.GetHubContext<Hubsfile.MyHub>();
hubContext.Clients.All.SendControl(machine, code);
This (another function below) is working fine as the client is the webpage itself(i think).
hubContext.Clients.All.registerCard(ip, data);
But when I am trying to call a method that is from different client(a console application) , Hub context is not calling it.
Does Hub context doesnt work for clients outside of the Hub Application.
Edit:
Method in SignalR HUB:
public void SendControlKeys(string machine, string code)
{
Clients.All.SendControl(machine, code);
}
Method in Console client:
proxy.On<string, string>("SendControl", (ip, data) =>
{
Console.WriteLine("server called SendControl");
Console.WriteLine();
byte[] dataBytes = HexEncoding.GetBytes(data, out int i);
try
{
lock (Clients)
{
if (Clients.Count > 0)
{
foreach (KeyValuePair<string, StateObject> client in Clients)
{
if (isClientConnected(client.Value.workSocket))
{
if (client.Key == ip)
{
Send(client.Value.workSocket, dataBytes);
break;
}
}
}
}
}
}catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
});
You need to call the hub connection's Start()
method after setting up the callback on the proxy.
var proxy = con.CreateHubProxy("name");
proxy.On<T>(...);
con.Start().Wait();
Then, use a single parameter in your callback. Wrap the 2 parameters you have into a single class/object.
Apart from that, ensure the name of the hub in your CreateHubProxy call is valid, that is the name of the SignalR Hub in your ASP.net application (in your case MyHub
).