Web サイト A ( ) で SignalR 永続接続を使用していlocalhost:6599
ます。A/index.html をレンダリングして /goose (私の接続名!) に接続すると、SSE 経由でグループが尊重されます。コードを Web サイト B にコピーし ( localhost:58660
)、$.connection を絶対 URL に変更すると ( http://localhost:6599/goose
)、Web サイト B の signalR クライアントは同じグループに送信されたメッセージを受信しません。
同時に、Web サイト B はメッセージを送信でき、Web サイト A のクライアントはそれらをグループで受信します。グループ メッセージからブロードキャストに変更すると、メッセージは Web サイト A と B の両方のクライアントに届きます。
ウェブサイト A の私のコード:
<div id="data"></div>
<script>
$(document).ready(function() {
var connection = $.connection('/goose', "group=123", true);
connection.start().done(function() {
connection.received(function(data) {
console.log(data);
$("#data").html(data);
});
connection.send("123:hooo");
}
);
});
</script>
サーバー側:
public class GooseConnection : PersistentConnection
{
protected override Task OnConnected(IRequest request, string connectionId)
{
var group = request.QueryString["group"];
return Groups.Add(connectionId, group);
}
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
// Messages are sent with the following format
// group:message
string[] decoded = data.Split(':');
string groupName = decoded[0];
string message = decoded[1];
// Send a message to the specified
return Groups.Send(groupName, message);
}
protected override Task OnDisconnected(IRequest request, string connectionId)
{
return Groups.Remove(connectionId, request.QueryString["group"]);
}
}
ウェブサイト B の私のコード:
var connection = null;
$(document).ready(function () {
connection = $.connection('http://localhost:6599/goose', "group=123", true);
connection.start({ jsonp: true }).done(function () {
connection.received(function (data) {
console.log(data);
alert('oooyeah');
$("#data").html(data);
});
connection.send("123:hooo");
}
);
});
function tryagain() {
connection.send("123:hooo");
}
ウェブサイト A からのトレース (フォーマットについて申し訳ありません):
[21:31:58 GMT+0000 (GMT Standard Time)] SignalR: Negotiating with
'/goose/negotiate'. jquery.signalR-1.0.0-rc2.min.js:10 [21:31:58 GMT+0000 (GMT Standard Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:6599/goose/connect?transport=serverSentEvents&connectionId=93b07a1b-779f-44e9-87f3-3eb201a97fdd&group=123&tid=0' jquery.signalR-1.0.0-rc2.min.js:10 [21:31:59 GMT+0000 (GMT Standard Time)] SignalR: EventSource connected jquery.signalR-1.0.0-rc2.min.js:10 [21:31:59 GMT+0000 (GMT 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.min.js:10 hooo localhost:18 [21:44:30 GMT+0000 (GMT Standard Time)] SignalR: EventSource readyState: 0 jquery.signalR-1.0.0-rc2.min.js:10 [21:44:30 GMT+0000 (GMT Standard Time)] SignalR: EventSource reconnecting due to the server connection ending jquery.signalR-1.0.0-rc2.min.js:10 [21:44:32 GMT+0000 (GMT Standard Time)] SignalR: EventSource calling close() jquery.signalR-1.0.0-rc2.min.js:10 [21:44:32 GMT+0000 (GMT Standard Time)] SignalR: EventSource reconnecting
Web サイト B からのトレース:
[21:30:33 GMT+0000 (GMT Standard Time)] SignalR: Auto detected cross domain url. jquery.signalR-1.0.0-rc2.min.js:10 [21:30:33 GMT+0000 (GMT Standard Time)] SignalR: Negotiating with 'http://localhost:6599/goose/negotiate'. jquery.signalR-1.0.0-rc2.min.js:10 [21:30:33 GMT+0000 (GMT Standard Time)] SignalR: SignalR: Initializing long polling connection with server. jquery.signalR-1.0.0-rc2.min.js:10 [21:30:33 GMT+0000 (GMT Standard Time)] SignalR: Attempting to connect to 'http://localhost:6599/goose/connect?transport=longPolling&connectionId=d01cebe3-28f6-4150-a606-b9d64224edd7&group=123&tid=3' using longPolling. jquery.signalR-1.0.0-rc2.min.js:10 [21:30:33 GMT+0000 (GMT Standard Time)] SignalR: Longpolling connected jquery.signalR-1.0.0-rc2.min.js:10 [21:30:33 GMT+0000 (GMT Standard Time)] SignalR: Attempting to connect to 'http://localhost:6599/goose?transport=longPolling&connectionId=d01cebe3-28f…cloud.Spotify.Goose.Connections.GooseConnection.123%22%5D&group=123&tid=10' using longPolling. jquery.signalR-1.0.0-rc2.min.js:10 [21:32:29 GMT+0000 (GMT Standard Time)] SignalR: Attempting to connect to 'http://localhost:6599/goose?transport=longPolling&connectionId=d01cebe3-28f…acloud.Spotify.Goose.Connections.GooseConnection.123%22%5D&group=123&tid=2' using longPolling. jquery.signalR-1.0.0-rc2.min.js:10
私が試したこと:
- 自動再接続を global.asax に追加します ( GlobalHost.HubPipeline.EnableAutoRejoiningGroups();)
- .start({jsonp:true}) を手動で設定する
- 各クライアントへのブロードキャスト var context = GlobalHost.ConnectionManager.GetConnectionContext(); context.Connection.Broadcast("これはハックでした"); これは機能します。
さらにデバッグに関するアドバイスをいただければ幸いです。アンディ