I'm following this quick tutorial on getting a SignalR project started, and in my Hub class, I have the following
using Microsoft.AspNet.SignalR.Hubs;
namespace MvcApplication8.Hubs
{
public class ChatHub : Hub
{
public void BroadcastMessage(string message)
{
Clients.writeMessage(message);
}
}
}
Client code:
$(document).ready(function () {
var chat = $.connection.chatHub;
chat.writeMessage = function(msg) {
$("#messages").append("<li>" + msg + "</li>");
};
$("#buttonSubmit").click(function () {
chat.broadcastMessage($("#txtInput").val());
});
$.connection.hub.start();
});
However I'm getting a compile time error saying:
'Microsoft.AspNet.SignalR.Hubs.HubConnectionContext' does not contain a definition for 'writeMessage' and no extension method 'writeMessage' accepting a first argument of type 'Microsoft.AspNet.SignalR.Hubs.HubConnectionContext' could be found (are you missing a using directive or an assembly reference?)
Where went wrong?
I installed SignalR into my project from http://nuget.org/packages/microsoft.aspnet.signalr using the package manager console "Install-Package Microsoft.AspNet.SignalR -Pre"
SignalR requires that all HTTP requests for a specific connection be handled by the same server process. When SignalR is running on a server farm (multiple servers), "sticky sessions" must be used. "Sticky sessions" are also called session affinity by some load balancers.
The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command.
Did you create the corresponding client-function?
<script type="text/javascript">
$(function () {
var chat = $.connection.chat;
chat.writeMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$.connection.hub.start();
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With