Reputation: 5
I followed the documentation at https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs to create a simple chat application using SignalR Hubs.
I can't get it to work and don't understand what I'm doing wrong?
I keep getting the following error:
SignalR: Connection must be started before data can be sent. Call .start() before .send()
Hub class:
public class Chat : Hub
{
public void Send(string message)
{
Clients.addMessage(message);
}
}
Client:
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR.min.js" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
// Proxy created on the fly
var chat = $.connection.chat;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$("#broadcast").click(function () {
// Call the chat method on the server
chat.send($('#msg').val())
.done(function () {
console.log('Success!');
})
.fail(function (e) {
console.warn(e);
});
});
// Start the connection
$.connection.hub.start();
});
</script>
</head>
<body>
<div>
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</ul>
</div>
</body>
Packages:
<packages>
<package id="Newtonsoft.Json" version="4.0.8" />
<package id="SignalR.Server" version="0.4.0.0" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
<package id="SignalR.Hosting.AspNet" version="0.4.0.0" />
<package id="jQuery" version="1.6.4" />
<package id="SignalR.Js" version="0.4.0.1" />
<package id="SignalR" version="0.4.0" />
<package id="jQuery.Color" version="1.0" />
</packages>
Upvotes: 0
Views: 2055
Reputation: 17883
Have you looked in the developer tools for your browser to see if there are any errors?
It's possible that SignalR is unable to start up on the client due to getting an error (e.g. 500) when trying to connect to the server.
Upvotes: 1