1

I am using SignalR based on examples from https://github.com/SignalR/Samples. I am new to this but got it to work in my web app for chat room type of concept. But now I am trying to get a user to user chat functionality done using this. How can I do so?

Do I have to setup a separate connection for each of the chat sessions? Meaning user1 on browser1 is chatting with 5 people separately in single page. Do I need to have separate 5 SignalR connection from user1 to the server?

Meaning do I have to render this section next to each of my chat elements for those 5 different end points for user1? or can I just have one SignalR connection? if I only have one how to I update the correct chat controls from the server to display the response from end users?

@section scripts {
    <script src="@Url.Content("~/Scripts/jquery.signalR-1.0.0-rc1.min.js")" type="text/javascript"></script>
    <script src="/signalR/hubs" type="text/javascript"></script>

    <script>
        $(function () {
            var chat = $.connection.chat;

            chat.client.send = function (message) {
                $('#message').append('<li>' + message + '</li>');
            };

            $.connection.hub.start().done(function () {
                $('#send').click(function () {
                    chat.server.send($('#msg').val());
                });
            });
        });
    </script>
}

Is there a example somewhere I can use?

Mr_Green
  • 40,727
  • 45
  • 159
  • 271
Justin Homes
  • 3,739
  • 9
  • 49
  • 78

1 Answers1

0

From back end u send to the client by his connection id: // Call send on to a specific connection

Clients.Client(Context.ConnectionId).send(message);

and on the client you get the client id for the hub connection.

$.connection.hub.id
Reno
  • 1,291
  • 4
  • 17
  • 29