title: Signalr: Cannot send message back when user send message for specific user
body: <p>I am new in using <code>SignalR</code>. When I send a message to a particular user are:</p>
  
  <ol>
  <li>I do not get the message back (I do not see it on the screen).</li>
  <li>The user receives a notice can not send a message back.</li>
  </ol>
  
  <p>That means sending a message can only be in one direction.
  How to do that two users can send messages to each other?**</p>
  
  <p>There is my classes i use:</p>
  
  <pre><code>[HubName("TSChatHub")]
  [Authorize]
  public class ChatHub : Hub
  {
  
      private readonly static ConnectionMapping&lt;string&gt; _connections =
          new ConnectionMapping&lt;string&gt;();
  
      public void SendChatMessage(string who, string message)
      {
          string name = Context.User.Identity.Name;
  
          foreach (var connectionId in _connections.GetConnections(who))
          {
              Clients.Client(connectionId).addChatMessage(name + ": " + message);
          }
      }
  
      public override Task OnConnected()
      {
          string name = Context.User.Identity.Name;
  
          _connections.Add(name, Context.ConnectionId);
  
          return base.OnConnected();
      }
  
      public override Task OnDisconnected(bool stopCalled)
      {
          string name = Context.User.Identity.Name;
  
          _connections.Remove(name, Context.ConnectionId);
  
          return base.OnDisconnected(stopCalled);
      }
  
      public override Task OnReconnected()
      {
          string name = Context.User.Identity.Name;
  
          if (!_connections.GetConnections(name).Contains(Context.ConnectionId))
          {
              _connections.Add(name, Context.ConnectionId);
          }
  
          return base.OnReconnected();
      }
  }
  
    public class ConnectionMapping&lt;T&gt;
  {
      private readonly Dictionary&lt;T, HashSet&lt;string&gt;&gt; _connections =
         new Dictionary&lt;T, HashSet&lt;string&gt;&gt;();
  
      public int Count
      {
          get
          {
              return _connections.Count;
          }
      }
  
      public void Add(T key, string connectionId)
      {
          lock (_connections)
          {
              HashSet&lt;string&gt; connections;
              if (!_connections.TryGetValue(key, out connections))
              {
                  connections = new HashSet&lt;string&gt;();
                  _connections.Add(key, connections);
              }
  
              lock (connections)
              {
                  connections.Add(connectionId);
              }
          }
      }
  
      public IEnumerable&lt;string&gt; GetConnections(T key)
      {
          HashSet&lt;string&gt; connections;
          if (_connections.TryGetValue(key, out connections))
          {
              return connections;
          }
  
          return Enumerable.Empty&lt;string&gt;();
      }
  
      public void Remove(T key, string connectionId)
      {
          lock (_connections)
          {
              HashSet&lt;string&gt; connections;
              if (!_connections.TryGetValue(key, out connections))
              {
                  return;
              }
  
              lock (connections)
              {
                  connections.Remove(connectionId);
  
                  if (connections.Count == 0)
                  {
                      _connections.Remove(key);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>There is my View:</p>
  
  <pre><code>  &lt;div class="chatcontainer"&gt;
      &lt;input type="text" id="message" /&gt;
      &lt;input type="button" id="sendmessage" value="Send" /&gt;
      &lt;input type="hidden" id="displayname" /&gt;
      &lt;ul id="discussion"&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  
   $(function () {
          // Declare a proxy to reference the hub. 
          var chat = $.connection.TSChatHub;
          debugger;
          // Create a function that the hub can call to broadcast messages.
          chat.client.addChatMessage = function (name, message) {
              // Add the message to the page. 
              $('#discussion').append('&lt;li&gt;&lt;strong&gt;' + htmlEncode(name)
                  + '&lt;/strong&gt;:&amp;nbsp;&amp;nbsp;' + htmlEncode(name) + '&lt;/li&gt;');
          };
          // Get the user name and store it to prepend to messages.
         // $('#displayname').val(prompt('Enter your name:', ''));
          // Set initial focus to message input box.  
          $('#message').focus();
          // Start the connection.
          $.connection.hub.start().done(function () {
              console.log('Now connected, connection ID=' + $.connection.hub.id);
              $('#sendmessage').click(function () {
                  // Call the Send method on the hub. 
                  chat.server.sendChatMessage($('#message').val());
                  // Clear text box and reset focus for next comment. 
                  $('#message').val('').focus();
              });
          }).fail(function () { console.log("Could not connect"); });
      });
  
   // This optional function html-encodes messages for display in the page.
      function htmlEncode(value) {
          var encodedValue = $('&lt;div /&gt;').text(value).html();
          return encodedValue;
      }
  </code></pre>
  
  <p><strong>Anyone has a solution to help me</strong></p>