0

we have a project with 1 server and 2 clients

  1. server (webapi c#-mvc) : that is run on https:domain.com:2020.
  2. client1 : android app
  3. client2 : raspberry device (as an IoT device)

these two clients use WebApis to connect to the server and get and post commands and change status in database with api calls.

problem : clients have to do polling (real-time) to the server to find if there is a change in database to update their status. what can i use for this polling ? i thinks socket is the best but i don't know how should i use socket in my webapi, i saw a lot of examples but all of them are running on console app.

i found this example but i think it's not complete code and i don't know how should i use it in my webapi controllers. should i inherit of it or not?

thanks in advance :)

1 Answer 1

1

There is a library for this use case - SignalR , easy to use and it works for 4 transport protocol: websocket, forever frames, server sent and long polling. Another approach would be using native websocket support ,but in this case you would need to maintain the state of websocket ( same with any socket if you prefer).

SignalR needs client Library (or you can write one after reading the specifications) and officially available for c# and JavaScript, you can find libraries in some programming languages such as java and python , created by community.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks but i think signalR use websocket as long polling protocol (that is not our prefer)... if i'm wrong, let me know if i can use signalR for sending status to just one specific user not broadcast to all clients. i can't find a good example
Example you have mentioned is also websocket sample, being said that SignalR will fall back to other transport protocol if websocket is not available also you can disable it in the configuration. You can send information to specific client based on client Id or if you map it with Identity you can use user id to push data to specific user.
Hope this link would give some insights: stackoverflow.com/q/19522103/3576971
Just a point - websocket and long polling are two different transport protocols with respect to their behaviour and performance. You can read more at github.com/aspnet/SignalR/blob/master/specs/…
great, i will try to do your suggestions and i will send the result here :) thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.