Home > Blockchain >  Communicate with SignalR server application from another Windows process
Communicate with SignalR server application from another Windows process

Time:09-06

I have followed the guide from Microsoft for getting started with SignalR. This worked perfectly, and I was able to publish and deploy the application to IIS.

Now I need to communicate with the .NET application from another Windows process (specifically a Delphi program). What I want to do is to tell the .NET application to send SignalR message (i.e. invoke a method on all connected clients).

How can I accomplish this?

I'm not sure how the .NET application is being executed - does it have its own Windows process that I could send Windows messages to? Or would it be easier to send a local HTTP GET/POST request from the Delphi program to localhost? If so, how can I make the SignalR application handle it?

CodePudding user response:

You can create a controller and inject the IHubContext<ChatHub>. Use the hub context to send message to clients.

public class MessageController : Controller 
{
    private readonly IHubContext<ChatHub> _hubContext;

    public MessageController(IHubContext<MessageHub> hubContext)
    {
        _hubContext = hubContext;
    }

    [HttpPost]
    public async Task<IActionResult> SendMessage([FromForm] string message)
    {
        await _hubContext.Clients.All.SendAsync("ReceiveMessage", message);
        return Ok();
    }
}

Then call this endpoint from your delphi app.

  • Related