I've scoured the site, coming across SignalR OnConnected and OnDisconnected not firing and similar, but the solution does not apply in my case. I already do have the client methods registered.
Additionally, the OnConnected method of my hub does fire when running on my local box. It simply does not fire when deployed. All other methods work fine, however. For the present, I've created a work-around as such:
<script>
$(function () {
var myHub = $.connection.myHub;
myHub.client.clientMessage = function (message) { alert(message); };
// Start the connection.
$.connection.hub.start().done(function () {
myHub.server.superfluousMethodToDoSameThingInOnConnect();
});
});
</script>
I would really like to stop using this second call, however, and simply have OnConnected
work properly as it should. What is necessary on my deployment server to have it work the same?
For reference, my SignalR is version 1.2.2 (limited to .NET 4.0, for now) incorporated into an MVC site (with no errors, otherwise). My dev box is Windows 7 hosting in IIS Express 8.5 The deployment box is Winows Server 2003 hosting in IIS V6.0.
Edit 1: I've included a
myHub.connection.stateChanged(function (change) { alert("State: " + change.newState); });
for debugging, and when the page loads, it displays popup of "State: 0" followed by a popup of "State: 1" a short time later, and a "State: 4" when I leave the page, so it looks like my connection itself is behaving correctly. This functions the same both locally and on the deploy server.
Edit 2: To test further, I have updated the methods in the hub as below:
public override Task OnConnected()
{
Groups.Add(Context.ConnectionId, Context.User.Identity.Name);
Clients.All.clientMessage("OnConnected:: ID: " + Context.ConnectionId + " USER: " + Context.User.Identity.Name);
return base.OnConnected();
}
public void SuperfluousMethodToDoSameThingInOnConnect()
{
Clients.All.clientMessage("SuperfluousMethodToDoSameThingInOnConnect:: ID: " + Context.ConnectionId + " USER: " + Context.User.Identity.Name);
}
Results of this testing show that only the text sent from SuperfluousMethodToDoSameThingInOnConnect
is shown back to the Caller. However, other clients (tested in other browser windows) see both the text from OnConnected
and SuperfluousMethodToDoSameThingInOnConnect
.
Additionally, when I try to send a message back to the caller using Context.Groups(Context.User.Identity.Name)
then the message is not sent. However, if I move the group registration line Groups.Add(Context.ConnectionId, Context.User.Identity.Name)
from OnConnected
into SuperfluousMethodToDoSameThingInOnConnect
, then messages can be sent using Groups.Add(Context.ConnectionId, Context.User.Identity.Name)
. This seems extremely bizarre, as I can see that the OnConnected
method is called, but the Group is not really registered?
Really at a loss for anything to explain this erratic behavior.
Edit 3: Pushed the web app out to a Windows Server 2012 VM, where I found it works correctly, same as my local dev box. Is it that SignalR does not fully work on IIS 6?