0

I got a .NET Core web API hosted on the server and there's a remote client machine (Not in the same network and no relation to the server or the network)

In a normal scenario, client would make call to the Web API and GET/POST data but my requirement is for the Web API to call the client and get certain information from the client. Say, Web API wants to get details about client machines current process details.

Assumptions:

-The Web API already knows the following details about the client:

IP Address, UUID, Mac address, Machine name, Work Group

-There can be over 100,000 client machines (No limit)

-Web API needs to know the details of the client instantly on a button click

Is there a way to implement this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
chamara
  • 12,649
  • 32
  • 134
  • 210
  • Look at WebSockets, SignalR, Firebase, Socket.io and alternatives to these. – Prateek Shrivastava Jan 20 '21 at 22:45
  • What clients are you talking about? Cellphones? PCs? Servers? – Vincent Jan 20 '21 at 23:00
  • @PrateekShrivastava No, that's not a valid approach here, unless you're suggesting having 100k open websockets connections at the same time, and the insane amount of costs associated. – Camilo Terevinto Jan 20 '21 at 23:06
  • This is just too broad, you should hire someone with more knowledge or fix those requirements. A server cannot magically start a connection on a client, the client needs to expose some kind of service – Camilo Terevinto Jan 20 '21 at 23:07
  • @Vincent Can be Windows servers or PCs. – chamara Jan 20 '21 at 23:22
  • @PrateekShrivastava thak you for the comment. I'm having a look a SignalR – chamara Jan 20 '21 at 23:22
  • @CamiloTerevinto I was doing a bit of research based on the PrateekShrivastava's comment. It feels like SignalR could work – chamara Jan 20 '21 at 23:24
  • @charama if the clients are unable to host a server of some sort exposed to the internet, websockets/signalR is the way to go. Make sure to investigate how much load your infrastructure can handle. https://stackoverflow.com/questions/17448061/how-many-system-resources-will-be-held-for-keeping – Vincent Jan 21 '21 at 00:23

2 Answers2

1

You can use SignalR, it will open a conenction between both client and server. Once you need to fetch data, send a signalR request (ping) to the client with a specific action Name, on wich the client will act and call a given endpoint (API) giving you the needed information. SignalR implementation on the backend is very straight forward, and it depends on your client technology to choose any add-on library.

RamyRahman
  • 76
  • 7
-1

Assuming the clients are not able to host some sort of webservice themselves, you can accomplish this by using sockets.

If you are already hosting a web api on IIS you may be able to implement the websocket protocol. A separate IIS feature needs to be checked in server roles on the server, allowing you to upgrade incoming connections to a websocket connection.

Have the client initiate a connection on startup and save the state of the socket in the server.

This enables two-way communication from your server to the client, and from the client to the server.

More information about this can be found here:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-5.0

https://www.rfc-editor.org/rfc/rfc6455

Community
  • 1
  • 1
Vincent
  • 2,073
  • 1
  • 17
  • 24
  • This asumes it would be valid to have 100k open web sockets connections all the time, as the server cannot magically open the connection on its own. This approach is just not valid but the problem is that this question is too broad and the OP should just hire someone more knowledgeable – Camilo Terevinto Jan 20 '21 at 23:05
  • Yes this assumes 100k open socket connection, but unless the client can host a server, this is - appart from some long polling strategies - the only solution that meets the requirements. – Vincent Jan 21 '21 at 00:04