Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke client side method synchronously with SignalR

Tags:

signalr

How can the web server invoke a method on the client synchronously using SignalR? The key part here is that the server should wait for client to send data back to the server before continuing on?

Basically I'm looking to treat a client method invoke like a WCF service request. Invoke the client and wait for the data to be returned.

like image 751
Matt Avatar asked Jan 07 '13 16:01

Matt


1 Answers

SignalR does not provide a way to synchronously invoke client-side methods.

To achieve the same functionality as a synchronous call, you could pass some sort of invocation ID as an argument to your client-side method. The client could then invoke a server-side method like ClientMethodCompleted with its invocation ID when the client-side method is done. Basically you will be implementing your own ACK.

If you go this route, you will have to track the client invocations along with their respective ID's on the server. You can then execute whatever logic you would have done after a synchronous call in the ClientMethodCompleted method on the server.

This should be fairly simple if you are invoking the method on only one client. If you are invoking the method on multiple clients you will have to keep track of which clients you are invoking your method on so you can ensure all the clients have acknowledged the invocation before running your followup code.

I would also make sure that you periodically clean up the data structure storing unacknowledged client invocations if you are at all worried about a DOS attack, since this would be an obvious attack vector that could allow a malicious client blowup memory consumption.

like image 100
halter73 Avatar answered Oct 29 '22 15:10

halter73