SignalR client function not called when transport = serverSentEvents

On my machines, I found that SignalR client functions are not being called in Chrome.

My SignalR test app works fine with IE9, Firefox and even Safari on my iphone. Looking at Fiddler, these browsers seem to be discussing transport = longPolling. But Chrome negotiates a connection with transport = serverSentEvents and I guess that's why client functions are not called in Chrome.

More details: I am using full IIS (not IIS express) on Windows 7. I am using SignalR version 1.0.0-rc2. I disabled AVG firewall and Windows firewall is not working. Chrome is version 24.0.1312.56, and was up to date at the time of writing. The application is called on localhost.

In Chrome, the signalR connection seems to be OK - the $ .connection.hub.start () function. The callback function is called. But after that, the client function is never called, even if other browsers work fine.

In the client code, I have enabled logging with

$.connection.hub.logging = true;

      

I see log messages in the Chrome javascript console that correspond to a successful connection. For reference, these log messages

[20:22:16 GMT+0800 (W. Australia Standard Time)] SignalR: Negotiating with '/SignalRChat-RC/signalr/negotiate'. jquery.signalR-1.0.0-rc2.js:54
[20:22:16 GMT+0800 (W. Australia Standard Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost/SignalRChat-RC/signalr/connect?transport=serverSentEvents&…7-22c5dbf27e0d&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=3' jquery.signalR-1.0.0-rc2.js:54
[20:22:16 GMT+0800 (W. Australia Standard Time)] SignalR: EventSource connected jquery.signalR-1.0.0-rc2.js:54
[20:22:16 GMT+0800 (W. Australia Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 40000 and a connection lost timeout of 60000 jquery.signalR-1.0.0-rc2.js:54

      

But when running the method on the client side, no messages are logged in the Chrome javascript console.

Interestingly, the submit method works in Chrome. Other clients show the message sent from Chrome even through Chrome itself, can't see it. The app is pretty much a chat app from the signalR tutorial at http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr

If I explicitly specify longPolling in the start method i.e.

$.connection.hub.start({ transport: 'longPolling' })

      

then Chrome works fine. But I expected to be able to let the browsers discuss their relationship and everything would work.

For reference, the relevant part of my client code looks like this:

$(function () {
    // Turn on logging to the javascript console
    $.connection.hub.logging = true;

    // set up an error-handling function
    $.connection.hub.error(function (err) {
        alert("Error signalR:" + JSON.stringify(err));
    });

    // Declare a proxy to reference the hub.  
    var chat = $.connection.chatHub;

    // Create a function that the hub can call to broadcast messages.
    // This function is never called when running in Chrome with the default signalR connection
    chat.client.broadcastMessage = function (name, message) {
        // Html encode display name and message.  
        var encodedName = $('<div />').text(name).html();
        var encodedMsg = $('<div />').text(message).html();
        // Add the message to the page.  
        $('#discussion').append('<li><strong>' + encodedName
            + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
    };

    // 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. 
    // Use $.connection.hub.start({ transport: 'longPolling' }) for reliability
    // Use $.connection.hub.start() to demonstrate that Chrome doesn't receive messages
    $.connection.hub.start().done(function () {
        // Enable the "Send" button
        $('#sendmessage').removeAttr('disabled');
        $('#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();
        });
    });
});

      

Anyone can figure out what I am doing wrong?

+3


source to share


3 answers


I tried the sample on Win7 Google Chrome 24 and it works great.

You can eliminate Fiddler installation and set breakpoints in javascript



POST /signalr/send?transport=serverSentEvents&connectionId=6ff0bffa-c31e-4d85-9aff-24f4528555ee HTTP/1.1
Host: localhost:43637
Connection: keep-alive
Content-Length: 113
Accept: application/json, text/javascript, */*; q=0.01
Origin: 
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17
Content-Type: application/x-www-form-urlencoded
Referer: /index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

data=%7B%22H%22%3A%22chathub%22%2C%22M%22%3A%22Send%22%2C%22A%22%3A%5B%22gus%22%2C%22hello%22%5D%2C%22I%22%3A0%7D

      

+2


source


Maybe it has something to do with buffering responses.



https://github.com/SignalR/SignalR/issues/1944

0


source


Try installing EnableJSONP = False

on a server hub. This fixed a similar problem I was having.

0


source







All Articles