admin管理员组文章数量:1203207
I'm trying to put together a simple "Hello World" style application with SignalR. The slightly complicating factor is that the SignalR hubs need to be self-hosted, not in IIS/ASP.NET. I've got the server-side working, so far as I can tell, and it's available on port 8080, but I'm having trouble wiring up the client. The problem I'm bumping up against at the moment is that the SignalR client seems to be ignoring the port on the URL that I specify.
Specifically, I've got this code here:
<head runat="server">
<script type="text/javascript" src="/Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/Scripts/json2.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery.signalR-0.5.3.js"></script>
<script type="text/javascript" src="http://<%=Request.Url.Host %>:8080/signalr/hubs"></script>
<title>SignalR Test</title>
</head>
<body>
<script type="text/javascript">
$(function () {
// Wire up the client to the SignalR server on the same host
// as the source of this page, but on port 8080.
$.connection.url = "http://<%=Request.Url.Host %>:8080/signalr";
var roomHub = $.connection.roomHub;
$('#echoButton').click(function () {
roomHub.echo($('#echoButton').val())
.error(function (err) {
alert(err);
});
});
$.connection.hub.start({ transport: 'auto', xdomain: true })
.done(function () {
console.log('Connected.');
})
.fail(function (e) {
console.log('Unable to connect:' + e);
});
});
</script>
The :8080/signalr/hubs script loads successfully, and it looks good, i.e., it has the definition for the roomHub
in it, so I know that the server is up and running.
However, when $.connection.hub.start()
runs, it seems like it should try to open up a connection for a URL something like :8080/signalr/signalr/negotiate?=1353072553935. Instead, Firebug tells me that it's ignoring the 8080 portion, and is instead trying to negotiate a connection with the URL ?=1353072553935. And of course, that doesn't work - there's no SignalR service listening on port 80, just the regular web server - so it fails with the message, "Unable to connect:SignalR: Error during negotiation request".
I should also note that in the jquery.signalR-0.5.3.js file, the bit of code that parses out the connection does indeed seem to ignore the port:
// Resolve the full url
parser.href = connection.url;
if (!parser.protocol || parser.protocol === ":") {
connection.protocol = window.document.location.protocol;
connection.host = window.document.location.host;
connection.baseUrl = connection.protocol + "//" + connection.host;
}
else {
connection.protocol = parser.protocol;
connection.host = parser.host;
connection.baseUrl = parser.protocol + "//" + parser.host;
}
// Set the websocket protocol
connection.wsProtocol = connection.protocol === "https:" ? "wss://" : "ws://";
Is this a bug? Or have I misunderstood something?
I'm trying to put together a simple "Hello World" style application with SignalR. The slightly complicating factor is that the SignalR hubs need to be self-hosted, not in IIS/ASP.NET. I've got the server-side working, so far as I can tell, and it's available on port 8080, but I'm having trouble wiring up the client. The problem I'm bumping up against at the moment is that the SignalR client seems to be ignoring the port on the URL that I specify.
Specifically, I've got this code here:
<head runat="server">
<script type="text/javascript" src="/Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/Scripts/json2.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery.signalR-0.5.3.js"></script>
<script type="text/javascript" src="http://<%=Request.Url.Host %>:8080/signalr/hubs"></script>
<title>SignalR Test</title>
</head>
<body>
<script type="text/javascript">
$(function () {
// Wire up the client to the SignalR server on the same host
// as the source of this page, but on port 8080.
$.connection.url = "http://<%=Request.Url.Host %>:8080/signalr";
var roomHub = $.connection.roomHub;
$('#echoButton').click(function () {
roomHub.echo($('#echoButton').val())
.error(function (err) {
alert(err);
});
});
$.connection.hub.start({ transport: 'auto', xdomain: true })
.done(function () {
console.log('Connected.');
})
.fail(function (e) {
console.log('Unable to connect:' + e);
});
});
</script>
The :8080/signalr/hubs script loads successfully, and it looks good, i.e., it has the definition for the roomHub
in it, so I know that the server is up and running.
However, when $.connection.hub.start()
runs, it seems like it should try to open up a connection for a URL something like http://app.dev.alanta.com:8080/signalr/signalr/negotiate?=1353072553935. Instead, Firebug tells me that it's ignoring the 8080 portion, and is instead trying to negotiate a connection with the URL http://app.dev.alanta.com/signalr/signalr/negotiate?=1353072553935. And of course, that doesn't work - there's no SignalR service listening on port 80, just the regular web server - so it fails with the message, "Unable to connect:SignalR: Error during negotiation request".
I should also note that in the jquery.signalR-0.5.3.js file, the bit of code that parses out the connection does indeed seem to ignore the port:
// Resolve the full url
parser.href = connection.url;
if (!parser.protocol || parser.protocol === ":") {
connection.protocol = window.document.location.protocol;
connection.host = window.document.location.host;
connection.baseUrl = connection.protocol + "//" + connection.host;
}
else {
connection.protocol = parser.protocol;
connection.host = parser.host;
connection.baseUrl = parser.protocol + "//" + parser.host;
}
// Set the websocket protocol
connection.wsProtocol = connection.protocol === "https:" ? "wss://" : "ws://";
Is this a bug? Or have I misunderstood something?
Share Improve this question edited Feb 26, 2015 at 17:17 Ken Smith asked Nov 16, 2012 at 13:53 Ken SmithKen Smith 20.4k17 gold badges103 silver badges151 bronze badges1 Answer
Reset to default 24Well, I could swear that I'd tried this and it didn't work, but as I was troubleshooting it some more, I changed the URL assignment from this:
$.connection.url = "http://<%=Request.Url.Host %>:8080/signalr";
To this:
$.connection.hub.url = "http://<%=Request.Url.Host %>:8080/signalr";
And to be sure, this is how it's documented here. I thought that I'd seen it documented the first way somewhere, but I can't find it now. Oh well. Chalk this one up to my not paying enough attention.
本文标签: javascriptSignalR js client seems to be ignoring the url portStack Overflow
版权声明:本文标题:javascript - SignalR js client seems to be ignoring the url port - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738651981a2104921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论