title: SignalR not working : $.connection.client is null or undefined
body: <p>After spending two days getting this working with no success, finally I am asking this question here. </p>
  
  <p>Background: I am trying to use SignalR to send real-time data from my desktop application to all web pages. </p>
  
  <p>What I have is, a console application (this just to get concept working then will move it to active project) that needs to send real time data to a webpage built in asp .net. Both are using .Net 4.</p>
  
  <p>In IE9 it shows me error in debug mode at line "chat.client.broadcastMessage = " saying chat.client is null or undefined. </p>
  
  <p>In firfox, it doesn't show me that error but it's not working/not doing anything and the problem is the same as it's not showing me alert('asking for name'); window so I guess it's not getting there and throwing error before that.</p>
  
  <p>Here's my web page code. This is new separate web site project.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;SignalR Simple Chat&lt;/title&gt;
      &lt;style type="text/css"&gt;
          .container {
              background-color: #99CCFF;
              border: thick solid #808080;
              padding: 20px;
              margin: 20px;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="container"&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;
      &lt;!--Script references. --&gt;
      &lt;!--Reference the jQuery library. --&gt;
  
      &lt;script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="Scripts/jquery.json-2.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="Scripts/json2.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;!--Reference the SignalR library. --&gt;
  
      &lt;script src="Scripts/jquery.signalR-1.0.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;!--Reference the autogenerated SignalR hub script. --&gt;
      &lt;script src="signalr/hubs"&gt;&lt;/script&gt;
      &lt;!--Add script to update the page and send messages.--&gt; 
      &lt;script type="text/javascript"&gt;
          $(function () {
              alert('starting scrip');
              // Declare a proxy to reference the hub. 
              $.connection.hub.url = 'http://&lt;ipaddressORlochost&gt;:8080/chatroom';
              alert($.connection.hub);
              alert($.connection.hub.url);
              var chat = $.connection.chatHub;
              // Create a function that the hub can call to broadcast messages.
              alert(chat);
              chat.client.broadcastMessage = function (name, message) {
                  // Html encode display name and message. 
                  var encodedName = $('&lt;div /&gt;').text(name).html();
                  var encodedMsg = $('&lt;div /&gt;').text(message).html();
                  // Add the message to the page. 
                  $('#discussion').append('&lt;li&gt;&lt;strong&gt;' + encodedName
                      + '&lt;/strong&gt;:&amp;nbsp;&amp;nbsp;' + encodedMsg + '&lt;/li&gt;');
              };
              alert('asking for name');
              // 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({ jsonp:true}).done(function () {
                  $('#sendmessage').click(function () {
                      // Call the Send method on the hub. 
                      chat.server.send($('#displayname').val(), $('#message').val());
                      // Clear text box and reset focus for next comment. 
                      $('#message').val('').focus();
                  });
              });
          });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  -------------------------
  </code></pre>
  
  <p>I have tried removing below line and also adding "/signalr" at the end.</p>
  
  <p>$.connection.hub.url = 'http://:8080/chatroom'; </p>
  
  <p>Here's my desktop application (server) code.</p>
  
  <pre><code>class Program
      {
  
          static void Main(string[] args)
          {
  
  
              using (WebApplication.Start&lt;Startup&gt;(@"http://&lt;ipaddressORlochost&gt;:8080/chatroom"))
              {
  
                  while (true)
                  {
                     // GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;().Clients.All.addMessage("dsf","asdfd");
                      Console.WriteLine("Tags sent :" + DateTime.Now.ToString("HH:mm:ss"));
                      Thread.Sleep(3000);
                  }
              }
  
          }
  
   class Startup
      {
  
          public void Configuration(IAppBuilder app)
          {
              var config = new HubConfiguration { EnableCrossDomain=true };
              app.MapHubs(config);
          }
      }
  
      public class ChatHub : Hub
       {
          public void Send(string b,string a)
          {
            try
             {
                  Clients.All.broadcastMessage(b,a);
              }
               catch { }
          }
       }
  </code></pre>
  
  <p>ANY HELP WOULD BE REALLY APPRECIATED. </p>
  
  <p>Thanks All in advance. </p>
  
  <p>-------------- FOUND THE ANSWER ---------- HAVE EDIT THIS QUESTION AS CANNOT ANSWER MY OWN QUESTION WITHIN 8 HOURS</p>
  
  <p>Hi ALL</p>
  
  <p>Just in case if some one else having same problem. I have found answer/fixed. </p>
  
  <p>THANKS TO <strong><a href="https://stackoverflow.com/questions/12396233/connection-is-undefined-signalr-0-5-3-mvc4/16160077#16160077">Hatake Kakashi</a></strong></p>
  
  <p>Main issue was that $.connection is now changed to  $.hubConnection</p>
  
  <p>Here's what I had to change.</p>
  
  <p>Script in my web page. I have left commented code to show what's been replaced with what.</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
          $(function () {
              alert('starting scrip');
              // Declare a proxy to reference the hub. 
              // $.connection.hub.url = 'http://localhost:8080/chatroom';
              var conn = $.hubConnection('http://localhost:8080/chatroom');
  
              alert($.connection.hub);
              alert($.connection.hub.url);
  
              var chat = conn.createHubProxy('chatHub'); //$.connection.chatHub;
              // Create a function that the hub can call to broadcast messages.
              alert(chat);
              //            chat.client.broadcastMessage = function (name, message) {
              //                // Html encode display name and message. 
              //                var encodedName = $('&lt;div /&gt;').text(name).html();
              //                var encodedMsg = $('&lt;div /&gt;').text(message).html();
              //                // Add the message to the page. 
              //                $('#discussion').append('&lt;li&gt;&lt;strong&gt;' + encodedName
              //                    + '&lt;/strong&gt;:&amp;nbsp;&amp;nbsp;' + encodedMsg + '&lt;/li&gt;');
              //            };
              chat.on('addMessage', function (a, message) {
  
                  $('#discussion').append('&lt;li&gt;&lt;strong&gt;' + $('&lt;div /&gt;').text(a).html()
                                  + '&lt;/strong&gt;:&amp;nbsp;&amp;nbsp;' + $('&lt;div /&gt;').text(message).html() + '&lt;/li&gt;');
  
              });
  
              alert('asking for name');
              // 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.
              conn.logging = true;
              // Start the connection
              conn.start().done(function () {
                  alert("Now connected!");
              }).fail(function () {
                  alert("Could not Connect!");
              });
  
  
  //            $.connection.hub.start({ jsonp: true }).done(function () {
  //                $('#sendmessage').click(function () {
  //                    // Call the Send method on the hub. 
  //                    chat.server.send($('#displayname').val(), $('#message').val());
  //                    // Clear text box and reset focus for next comment. 
  //                    $('#message').val('').focus();
  //                });
  //            });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>And on the server side (desktop application), because it's one way only I don't need to anything in my ChatHub</p>
  
  <pre><code> static void Main(string[] args)
          {
  
  
              using (WebApplication.Start&lt;Startup&gt;(@"http://localhost:8080/chatroom"))
              {
  
                  while (true)
                  {
                      GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;().Clients.All.addMessage("dsf", "Tags sent :" + DateTime.Now.ToString("HH:mm:ss"));
                      Console.WriteLine("Tags sent :" + DateTime.Now.ToString("HH:mm:ss"));
                      Thread.Sleep(500);
                  }
              }
  
          }
  
   class Startup
      {
  
          public void Configuration(IAppBuilder app)
          {
              var config = new HubConfiguration { EnableCrossDomain=true };
              app.MapHubs(config);
          }
      }
   public class ChatHub : Hub
         {
              /public void Send(string b, string a)
             //{
             //    try
             //    {
             //        Clients.All.addMessage(b, a);
             //    }
             //    catch { }
             //}
         }
  </code></pre>
  
  <p>Hope this will help others. </p>