Use Case: I have a asp.net core web application with signalR core for messaging. :)
Problem: I have to receive messages from a socket connection [via System.Net.Sockets] (machine with own socket communication)
Is there any way to integrate the socket client in the web app (maybe Progamm.cs or Startup.cs?) And how can I get access to the signalR to forward the received message to the signalR Hub?
thx
I suggest you to read the stockticker sample on : https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr
I show you here a small sample which you can adapt to your application. You have to subscribe the messages from your own socket communication and then you can forward this messages to the connected clients.
Here is a small sample how to send the time from server to the clients. (The interesting part for you is the line
GlobalHost.ConnectionManager.GetHubContext<ClockHub>().Clients.All.sendTime(DateTime.UtcNow.ToString());
. Which this you can send something to all connected clients.My main class is a clock which sends the actual time to all connected clients:
}
In the startup I created a sigleton instance of this clock, which lives as long as the application is running.
My Hub:
Hub interface which defines the method, which the server can call:
This is the clients part:
How to inject hubcontext in asp.net core 2.x Call SignalR Core Hub method from Controller