0

I've been working with the asp.net MVC and WebApi application which I've wanted to implement the real-time updating and response of a server to client or vice versa, but I don't know where do I start in ios and android, I do know how Signalr works in MVC and WebApi. please see my sample implementation below. and how this is work.

WebApi Controller Extended

public abstract class ApiControllerWithHub<THub> : BaseApiController
where THub : IHub
{
    Lazy<IHubContext> hub = new Lazy<IHubContext>(
        () => GlobalHost.ConnectionManager.GetHubContext<THub>()
    );

    protected IHubContext Hub
    {
        get { return hub.Value; }
    }
}

ChatHub

[HubName("chatHub")]
public class ChatHub :Microsoft.AspNet.SignalR.Hub
{
    public void sendMessage(string msg)
    {
        Clients.All.hello("Hello " +  msg");
    }

}

SampleController

public class SampleController : ApiControllerWithHub<ChatHub>
{
    [Route("Hello")]
    [HttpGet]
    public IHttpActionResult Hello(string msg)
    {
        Hub.Clients.All.hello("Hello " +  msg);
        return Ok("Hello " + msg);
    }
}

HTML

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <script src="/Scripts/jquery-1.6.4.js"></script>
    <script src="/Scripts/jquery.signalR-2.2.1.js"></script>
    <script src="/signalr/hubs"></script>
    <script>
        $(document).ready (function() {

            // Reference the auto-generated proxy for the hub.

            var chathub = $.connection.chatHub;
            $(".btn").click(function () {
                var msg = "World!";
                //chatHub.server.sendMessage("World!"); 
                $.get("/api/v1/sample/hello?msg=" + msg , function (data) {
                    console.log(data);
                });
            });

            chathub.client.hello = function (data) {
                $(".pmsg").html(data);
            };
        });
    </script>
</head>
<body>
<button class="btn">click</button>
<h2>Message</h2>
<p class="pmsg"></p>
</body>
</html>

Now it is done with the Web API, how do I implement this in android and ios? I just want if this is possible implement with this both android and ios if it does please help me and ] give me some example how this Signalr hub can be accessed.

By the way, I found some Signalr library that can be used in android, here the link

Any answer would be appreciated, thanks in advance sir.

vaj90
  • 1,803
  • 3
  • 17
  • 17

0 Answers0